author | Bruce Momjian | |
Thu, 20 Jun 2002 16:00:44 +0000 (16:00 +0000) | ||
committer | Bruce Momjian | |
Thu, 20 Jun 2002 16:00:44 +0000 (16:00 +0000) |
(backslash-N).\N
(backslash-N). You might\N
backticks(
backticks
caption, as it was previously only
caption, as it was
Objectcovers aggregates, functions, operators, types, relations
Objectcovers aggregates, functions, operators,
+to the command name,
+to the command name, each object is listed with
display permissions).
display
one-shotalternative to the
one-shot
*), then
*), then syntax help on all
+to the command name to see any descriptions
+to the command name to see any
large object.
large object. Optionally, it associates the given
large
large objectscurrently stored in the database,
Query resultsincludes all tables, command responses,
Query resultsincludes all tables, command
Unalignedwrites all fields of a tuple on a line, separated
Alignedmode is the
HTMLand
LaTeXmodes
Unalignedwrites all fields of a tuple on a
Alignedmode is the standard, human-readable,
HTMLand
LaTeXmodes put out tables that are intended to
horizontalmode.
horizontalmode.
pipesymbol).
append(
append
\) commands.
\)
footo the value
bar. To retrieve
footo the value
bar. To retrieve the content of the variable, precede
soft
variable variablesof
soft linksor
variable variablesof
, all lines entered or from a scriptall
,queries
, all linesall
,queries
noexec, the queries are just shown but are
noexec, the queries are
SQL_ASCII.
rollback,
commit, or
nothing.
rollback,
commit, or
nothing. The default is to roll back the
+ linkend="APP-PSQL-prompting"+ endterm="APP-PSQL-prompting-title"> below.QUIET - This variable is equivalent to the command line option .- It is probably not too useful in interactive mode.+ This variable is equivalent to the command line option+ . It is probably not too useful in+ interactive mode.SINGLELINE - This variable is set by the command line option . You- can unset or reset it at run time.+ This variable is set by the command line option+ . You can unset or reset it at run time.SINGLESTEP - This variable is equivalent to the command line option .+ This variable is equivalent to the command line option+ .USER - The database user you are currently connected as. This is set every time- you connect to a database (including program start-up), but can be unset.+ The database user you are currently connected as. This is set+ every time you connect to a database (including program+ start-up), but can be unset.SQL Interpolation - An additional useful feature ofpsql variables- is that you can substitute (interpolate) them into- regular SQL statements. The syntax for this is again to prepend- the variable name with a colon (: ).+ An additional useful feature ofpsql + variables is that you can substitute (interpolate)+ them into regular SQL statements. The syntax for+ this is again to prepend the variable name with a colon+ (: ).testdb=>\set foo 'my_table' testdb=>SELECT * FROM :foo; - would then query the tablemy_table . The value of the- variable is copied literally, so it can even contain unbalanced quotes or- backslash commands. You must make sure that it makes sense where you put it.- Variable interpolation will not be performed into quoted SQL- entities.+ would then query the tablemy_table . The value of+ the variable is copied literally, so it can even contain unbalanced+ quotes or backslash commands. You must make sure that it makes sense+ where you put it. Variable interpolation will not be performed into+ quoted SQL entities.- A popular application of this facility is to refer to the last inserted- OID in subsequent statements to build a foreign key- scenario.- Another possible use of this mechanism is to copy the contents of a file- into a field. First load the file into a variable and then proceed as above.+ A popular application of this facility is to refer to the last+ inserted OID in subsequent statements to build a+ foreign key scenario. Another possible use of this mechanism is to+ copy the contents of a file into a field. First load the file into a+ variable and then proceed as above.testdb=>\set content '\'' `cat my_file.txt` '\'' testdb=>INSERT INTO my_table VALUES (:content); testdb=>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\'' - Observe the correct number of backslashes (6)! You can resolve it this way: After-psql has parsed this line, it passes-sed -e "s/'/\\\'/g" < my_file.txt to the shell. The shell- will do its own thing inside the double quotes and executesed - with the arguments-e ands/'/\\'/g .- Whensed parses this it will replace the two- backslashes with a single one and then do the substitution. Perhaps at- one point you thought it was great that all Unix commands use the same- escape character. And this is ignoring the fact that you might have to- escape all backslashes as well because SQL text constants- are also subject to certain interpretations. In that case you might- be better off preparing the file externally.+ Observe the correct number of backslashes (6)! You can resolve it+ this way: Afterpsql has parsed this+ line, it passessed -e "s/'/\\\'/g" < my_file.txt + to the shell. The shell will do its own thing inside the double+ quotes and executesed with the arguments+-e ands/'/\\'/g . When+sed parses this it will replace the two+ backslashes with a single one and then do the substitution. Perhaps+ at one point you thought it was great that all Unix commands use the+ same escape character. And this is ignoring the fact that you might+ have to escape all backslashes as well because+ SQL text constants are also subject to certain+ interpretations. In that case you might be better off preparing the+ file externally.- Since colons may legally appear in queries, the following rule applies: If the variable- is not set, the character sequencecolon+nameis not changed. In any- case you can escape a colon with a backslash to protect it from interpretation.- (The colon syntax for variables is standard SQL for embedded- query languages, such asecpg . The colon syntax for- array slices and type casts arePostgreSQL extensions,- hence the conflict.)+ Since colons may legally appear in queries, the following rule+ applies: If the variable is not set, the character sequence+colon+nameis not changed. In any case you can escape+ a colon with a backslash to protect it from interpretation. (The+ colon syntax for variables is standard SQL for+ embedded query languages, such asecpg .+ The colon syntax for array slices and type casts are+PostgreSQL extensions, hence the+ conflict.)Prompting - The promptspsql issues can be customized to- your preference. The three variablesPROMPT1 ,PROMPT2 ,- andPROMPT3 contain strings and special escape sequences- that describe the appearance of the prompt. Prompt 1 is the normal prompt- that is issued whenpsql requests a new query.- Prompt 2 is issued when more input is expected during query input because- the query was not terminated with a semicolon or a quote was not closed.- Prompt 3 is issued when you run an SQLCOPY - command and you are expected to type in the tuples on the terminal.+ The promptspsql issues can be customized+ to your preference. The three variablesPROMPT1 ,+PROMPT2 , andPROMPT3 contain strings+ and special escape sequences that describe the appearance of the+ prompt. Prompt 1 is the normal prompt that is issued when+psql requests a new query. Prompt 2 is+ issued when more input is expected during query input because the+ query was not terminated with a semicolon or a quote was not closed.+ Prompt 3 is issued when you run an SQL+COPY command and you are expected to type in the+ tuples on the terminal.- The value of the respective prompt variable is printed literally, except where- a percent sign (%) is encountered. Depending on the next- character, certain other text is substituted instead. Defined substitutions are:+ The value of the respective prompt variable is printed literally,+ except where a percent sign (%) is encountered.+ Depending on the next character, certain other text is substituted+ instead. Defined substitutions are:The full host name (with domain name) of the database server,- or[local] if the connection is over a- Unix domain socket, or-[local: >,/dir/name ]- if the Unix domain socket is not at the compiled in default+ or[local] if the connection is over a Unix+ domain socket, or+[local: /dir/name ]+ >, if the Unix domain socket is not at the compiled in defaultlocation.The host name of the database server, truncated after the- first dot, or[local] if the connection- is over a Unix domain socket.+ first dot, or[local] if the connection is+ over a Unix domain socket.%R - - In prompt 1 normally=, but^if in single-line- mode, and!if the session is disconnected from the database- (which can happen if\connect fails). In prompt 2 the- sequence is replaced by-,*, a single quote,- or a double quote, depending on whetherpsql - expects more input because the query wasn't terminated yet, because you are- inside a/* ... */ comment, or because you are inside- a quote. In prompt 3 the sequence doesn't resolve to anything.+++ In prompt 1 normally=, but^if+ in single-line mode, and!if the session is+ disconnected from the database (which can happen if+\connect fails). In prompt 2 the sequence is+ replaced by-,*, a single quote,+ or a double quote, depending on whether+psql expects more input because the+ query wasn't terminated yet, because you are inside a+/* ... */ comment, or because you are inside+ a quote. In prompt 3 the sequence doesn't resolve to anything.+% digits - - Ifdigits starts with-0x the rest of the characters are interpreted as a- hexadecimal digit and the character with the corresponding code is- substituted. If the first digit is0 the characters are- interpreted as on octal number and the corresponding character is- substituted. Otherwise a decimal number is assumed.+++ Ifdigits starts+ with0x the rest of the characters are+ interpreted as a hexadecimal digit and the character with the+ corresponding code is substituted. If the first digit is+0 the characters are interpreted as on octal+ number and the corresponding character is substituted. Otherwise+ a decimal number is assumed.+%: name : - - The value of thepsql , variable - class="parameter">name. See the section-- for details.+++ The value of thepsql , variable+name . See the+ section + endterm="APP-PSQL-variables-title"> for details.+%` command ` - - The output ofcommand , similar to- ordinaryback-ticksubstitution.+++ The output of + class="parameter">command, similar to ordinary+back-ticksubstitution.+- To insert a percent sign into your prompt, write%% . The- default prompts are equivalent to'%/%R%# ' for prompts 1- and 2, and'>> ' for prompt 3.+ To insert a percent sign into your prompt, write+%% . The default prompts are equivalent to+'%/%R%# ' for prompts 1 and 2, and+'>> ' for prompt 3.- This feature was shamelessly plagiarized fromtcsh .+ This feature was shamelessly plagiarized from+tcsh .Miscellaneous -psql returns 0 to the shell if it finished normally,- 1 if a fatal error of its own (out of memory, file not found) occurs, 2 if the- connection to the backend went bad and the session is not interactive, and 3 if- an error occurred in a script and the variableON_ERROR_STOP was- set.+psql returns 0 to the shell if it+ finished normally, 1 if a fatal error of its own (out of memory,+ file not found) occurs, 2 if the connection to the backend went bad+ and the session is not interactive, and 3 if an error occurred in a+ script and the variableON_ERROR_STOP was set.- Before starting up,psql attempts- to read and execute commands from the file$HOME/.psqlrc . It- could be used to set up the client or the server to taste (using the\set - andSET commands).+ Before starting up,psql attempts to read+ and execute commands from the file+$HOME/.psqlrc . It could be used to set up the+ client or the server to taste (using the\set + andSET commands).GNU readline -psql supports the readline and history libraries for- convenient line editing and retrieval. The command history is stored in a file- named.psql_history in your home directory and is reloaded when-psql starts up.- Tab-completion is also supported, although- the completion logic makes no claim to be an SQL parser.- When available,psql is automatically built to use these- features. If for some reason you do not like the tab completion, you can turn if off- by putting this in a file named.inputrc in your- home directory:+psql supports the readline and history+ libraries for convenient line editing and retrieval. The command+ history is stored in a file named.psql_history + in your home directory and is reloaded when+psql starts up. Tab-completion is also+ supported, although the completion logic makes no claim to be an+ SQL parser. When available,+psql is automatically built to use these+ features. If for some reason you do not like the tab completion, you+ can turn if off by putting this in a file named+.inputrc in your home directory:$if psqlset disable-completion on$endif- (This is not apsql but areadline - feature. Read its documentation for further details.)+ (This is not apsql but a+readline feature. Read its documentation+ for further details.)- If you have the readline library installed butpsql - does not seem to use it, you must make sure thatPostgreSQL 's- top-levelconfigure script finds it.configure - needs to find both the librarylibreadline.a - (or a shared library equivalent)-and the header filesreadline.h and-history.h (orreadline/readline.h and-readline/history.h ) in appropriate directories. If- you have the library and header files installed in an obscure place you- must tellconfigure about them, for example:+ If you have the readline library installed but+psql does not seem to use it, you must+ make sure thatPostgreSQL 's top-level+configure script finds it.+configure needs to find both the library+libreadline.a (or a shared library equivalent)+and the header files+readline.h andhistory.h + (orreadline/readline.h and+readline/history.h ) in appropriate directories.+ If you have the library and header files installed in an obscure+ place you must tellconfigure about them, for+ example:$ ./configure --with-includes=/opt/gnu/include --with-libs=/opt/gnu/lib ...- Then you have to recompilepsql (not necessarily- the entire code tree).+ Then you have to recompilepsql (not+ necessarily the entire code tree).- The GNU readline library can be obtained from the GNU- project's FTP server atftp://ftp.gnu.org .+ The GNU readline library can be obtained from the+ GNU project's FTP server at+ftp://ftp.gnu.org .- This section only shows a few examples specific topsql .- If you want to learn SQL or get familiar with-PostgreSQL , you might wish to read the Tutorial that- is included in the distribution.+ This section only shows a few examples specific to+psql . If you want to learn+ SQL or get familiar with+PostgreSQL , you might wish to read the+ Tutorial that is included in the distribution.- The first example shows how to spread a query over several lines of input.- Notice the changing prompt:+ The first example shows how to spread a query over several lines of+ input. Notice the changing prompt:testdb=>CREATE TABLE my_table ( testdb(>first integer not null default 0, testdb=>\set PROMPT1 '%n@%m %~%R%# ' peter@localhost testdb=>- Let's assume you have filled the table with data and want to take a look at it:+ Let's assume you have filled the table with data and want to take a+ look at it:peter@localhost testdb=> SELECT * FROM my_table;first | second(4 rows)- You can make this table look differently by using the\pset - command:+ You can make this table look differently by using the+\pset command:peter@localhost testdb=>\pset border 2 Border style is 2.- In some earlier lifepsql allowed the first- argument to start directly after the (single-letter) command. For- compatibility this is still supported to some extent but I am not- going to explain the details here as this use is discouraged. But- if you get strange messages, keep this in mind. For example+ In some earlier lifepsql allowed the+ first argument to start directly after the (single-letter)+ command. For compatibility this is still supported to some extent+ but I am not going to explain the details here as this use is+ discouraged. But if you get strange messages, keep this in mind.+ For exampletestdb=>\foo Field separator is "oo",-psql only works smoothly with servers of the- same version. That does not mean other combinations will fail outright,- but subtle and not-so-subtle problems might come up.+psql only works smoothly with servers+ of the same version. That does not mean other combinations will+ fail outright, but subtle and not-so-subtle problems might come+ up.- Pressing Control-C during acopy in(data sent to the- server) doesn't show the most ideal of behaviors. If you get a message- such asCOPY state must be terminated first,- simply reset the connection by entering\c - - .+ Pressing Control-C during acopy in(data sent to+ the server) doesn't show the most ideal of behaviors. If you get a+ message such asCOPY state must be terminated+ first, simply reset the connection by entering\c + - -.index 16c23d320ee4e3d98ec559c1dd56a309cb39e081..cfc8a5c0703555dd3cd21a466d150d4aadfdaf4c 100644 (file)
*** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.156 2002/05/21 22:59:00 tgl Exp $+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.157 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/* the table.*/void-DoCopy(const RangeVar *relation, bool binary, bool oids, bool from, bool pipe,- char *filename, char *delim, char *null_print)+DoCopy(const CopyStmt *stmt){+ RangeVar *relation = stmt->relation;+ char *filename = stmt->filename;+ bool is_from = stmt->is_from;+ bool pipe = (stmt->filename == NULL);+ List *option;+ DefElem *dbinary = NULL;+ DefElem *doids = NULL;+ DefElem *ddelim = NULL;+ DefElem *dnull = NULL;+ bool binary = false;+ bool oids = false;+ char *delim = "\t";+ char *null_print = "\\N";FILE *fp;Relation rel;- AclMode required_access = (from ? ACL_INSERT : ACL_SELECT);+ AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT);AclResult aclresult;+ /* Extract options from the statement node tree */+ foreach(option, stmt->options)+ {+ DefElem *defel = (DefElem *) lfirst(option);++ if (strcmp(defel->defname, "binary") == 0)+ {+ if (dbinary)+ elog(ERROR, "COPY: conflicting options");+ dbinary = defel;+ }+ else if (strcmp(defel->defname, "oids") == 0)+ {+ if (doids)+ elog(ERROR, "COPY: conflicting options");+ doids = defel;+ }+ else if (strcmp(defel->defname, "delimiter") == 0)+ {+ if (ddelim)+ elog(ERROR, "COPY: conflicting options");+ ddelim = defel;+ }+ else if (strcmp(defel->defname, "null") == 0)+ {+ if (dnull)+ elog(ERROR, "COPY: conflicting options");+ dnull = defel;+ }+ else+ elog(ERROR, "COPY: option \"%s\" not recognized",+ defel->defname);+ }++ if (dbinary)+ binary = intVal(dbinary->arg);+ if (doids)+ oids = intVal(doids->arg);+ if (ddelim)+ delim = strVal(ddelim->arg);+ if (dnull)+ null_print = strVal(dnull->arg);++ if (binary && ddelim)+ elog(ERROR, "You can not specify the DELIMITER in BINARY mode.");++ if (binary && dnull)+ elog(ERROR, "You can not specify NULL in BINARY mode.");+/** Open and lock the relation, using the appropriate lock type.*/- rel = heap_openrv(relation, (from ? RowExclusiveLock : AccessShareLock));+ rel = heap_openrv(relation, (is_from ? RowExclusiveLock : AccessShareLock));/* Check permissions. */aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),server_encoding = GetDatabaseEncoding();#endif- if (from)+ if (is_from){ /* copy from file to database */if (rel->rd_rel->relkind != RELKIND_RELATION){if (!pipe)FreeFile(fp);- else if (!from)+ else if (!is_from){if (!binary)CopySendData("\\.\n", 3, fp);* transaction to ensure that updates will be committed before lock is* released.*/- heap_close(rel, (from ? NoLock : AccessShareLock));+ heap_close(rel, (is_from ? NoLock : AccessShareLock));}index ae4e52f42a4b2393b8bfdad118f7c05b744a0ab7..4e9fe90e360b7cc19b9ef3362dee9b3db0fca07a 100644 (file)
*** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.93 2002/06/18 17:27:57 momjian Exp $+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.94 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/*/void-createdb(CreatedbStmt *stmt)+createdb(const CreatedbStmt *stmt){char *nominal_loc;char *alt_loc;index d2a3f40a34822113e5603519664ca84d19fddacc..37da8612a4c72abe8c44559ee5984e895184ad4e 100644 (file)
* Portions Copyright (c) 1994, Regents of the University of California** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.189 2002/06/18 17:27:57 momjian Exp $+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.190 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/{CopyStmt *newnode = makeNode(CopyStmt);- newnode->binary = from->binary;Node_Copy(from, newnode, relation);- newnode->oids = from->oids;- newnode->direction = from->direction;+ newnode->is_from = from->is_from;if (from->filename)newnode->filename = pstrdup(from->filename);- if (from->delimiter)- newnode->delimiter = pstrdup(from->delimiter);- if (from->null_print)- newnode->null_print = pstrdup(from->null_print);+ Node_Copy(from, newnode, options);return newnode;}index 85ff384479decec3afdeb191733a17342ed145d0..55f0be0558237e3791610e6a00b1f624fa1e77e9 100644 (file)
* Portions Copyright (c) 1994, Regents of the University of California** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.136 2002/06/18 17:27:57 momjian Exp $+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.137 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/static bool_equalCopyStmt(CopyStmt *a, CopyStmt *b){- if (a->binary != b->binary)- return false;if (!equal(a->relation, b->relation))return false;- if (a->oids != b->oids)- return false;- if (a->direction != b->direction)+ if (a->is_from != b->is_from)return false;if (!equalstr(a->filename, b->filename))return false;- if (!equalstr(a->delimiter, b->delimiter))- return false;- if (!equalstr(a->null_print, b->null_print))+ if (!equal(a->options, b->options))return false;return true;index 1c499f417d9619b7a4c1c05043407e660131685e..b7b2f6a693d2e1c25540592a51b6ade54b8c0458 100644 (file)
*** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.331 2002/06/19 15:40:58 momjian Exp $+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.332 2002/06/20 16:00:43 momjian Exp $** HISTORY* AUTHOR DATE MAJOR EVENT%typealter_column_default %typeadd_drop, drop_behavior, opt_drop_behavior -%typecreatedb_opt_list
-%typecreatedb_opt_item +%typecreatedb_opt_list, copy_opt_list
+%typecreatedb_opt_item, copy_opt_item %typeopt_lock, lock_type %typeopt_force, opt_or_replace %typeTriggerEvents %typeTriggerFuncArg -%typerelation_name, copy_file_name, copy_delimiter, copy_null, +%typerelation_name, copy_file_name, database_name, access_method_clause, access_method, attr_name,index_name, name, function_name, file_name%typeopt_interval %typeoverlay_placing, substr_from, substr_for -%typeopt_binary, opt_instead, opt_cursor -%typeopt_with_copy, index_opt_unique, opt_verbose, opt_full +%typeopt_instead, opt_cursor +%typeindex_opt_unique, opt_verbose, opt_full %typeopt_freeze +%typeopt_binary, opt_oids, copy_delimiter -%typecopy_dirn, direction, reindex_type, drop_type, +%typecopy_from ++%typedirection, reindex_type, drop_type, opt_column, event, comment_type%typefetch_how_many CURRENT_TIMESTAMP, CURRENT_USER, CURSOR, CYCLE,DATABASE, DAY_P, DEC, DECIMAL, DECLARE, DEFAULT,- DEFERRABLE, DEFERRED, DEFINER, DELETE_P, DELIMITERS, DESC,- DISTINCT, DO, DOMAIN_P, DOUBLE, DROP,+ DEFERRABLE, DEFERRED, DEFINER, DELETE_P, DELIMITER, DELIMITERS,+ DESC, DISTINCT, DO, DOMAIN_P, DOUBLE, DROP,EACH, ELSE, ENCODING, ENCRYPTED, END_TRANS, ESCAPE, EXCEPT,EXCLUSIVE, EXECUTE, EXISTS, EXPLAIN, EXTERNAL, EXTRACT,/******************************************************************************* QUERY :- * COPY [BINARY]FROM/TO - * [USING DELIMITERS] + * COPYFROM/TO [WITH options] + *+ * BINARY, OIDS, and DELIMITERS kept in old locations+ * for backward compatibility. 2002-06-18******************************************************************************/-CopyStmt: COPY opt_binary qualified_name opt_with_copy copy_dirn copy_file_name copy_delimiter copy_null+CopyStmt: COPY opt_binary qualified_name opt_oids copy_from+ copy_file_name copy_delimiter opt_with copy_opt_list{CopyStmt *n = makeNode(CopyStmt);- n->binary = $2;n->relation = $3;- n->oids = $4;- n->direction = $5;+ n->is_from = $5;n->filename = $6;- n->delimiter = $7;- n->null_print = $8;++ n->options = NIL;+ /* Concatenate user-supplied flags */+ if ($2)+ n->options = lappend(n->options, $2);+ if ($4)+ n->options = lappend(n->options, $4);+ if ($7)+ n->options = lappend(n->options, $7);+ if ($9)+ n->options = nconc(n->options, $9);$$ = (Node *)n;};-copy_dirn: TO { $$ = TO; }- | FROM { $$ = FROM; }+copy_from:+ FROM { $$ = TRUE; }+ | TO { $$ = FALSE; };/*| STDOUT { $$ = NULL; };-opt_binary: BINARY { $$ = TRUE; }- | /*EMPTY*/ { $$ = FALSE; }+++copy_opt_list:+ copy_opt_list copy_opt_item { $$ = lappend($1, $2); }+ | /* EMPTY */ { $$ = NIL; };-opt_with_copy:- WITH OIDS { $$ = TRUE; }- | /*EMPTY*/ { $$ = FALSE; }++copy_opt_item:+ BINARY+ {+ $$ = makeNode(DefElem);+ $$->defname = "binary";+ $$->arg = (Node *)makeInteger(TRUE);+ }+ | OIDS+ {+ $$ = makeNode(DefElem);+ $$->defname = "oids";+ $$->arg = (Node *)makeInteger(TRUE);+ }+ | DELIMITER opt_as Sconst+ {+ $$ = makeNode(DefElem);+ $$->defname = "delimiter";+ $$->arg = (Node *)makeString($3);+ }+ | NULL_P opt_as Sconst+ {+ $$ = makeNode(DefElem);+ $$->defname = "null";+ $$->arg = (Node *)makeString($3);+ }+ ;++/* The following exist for backward compatibility */++opt_binary:+ BINARY+ {+ $$ = makeNode(DefElem);+ $$->defname = "binary";+ $$->arg = (Node *)makeInteger(TRUE);+ }+ | /*EMPTY*/ { $$ = NULL; }+ ;++opt_oids:+ WITH OIDS+ {+ $$ = makeNode(DefElem);+ $$->defname = "oids";+ $$->arg = (Node *)makeInteger(TRUE);+ }+ | /*EMPTY*/ { $$ = NULL; };-/*- * the default copy delimiter is tab but the user can configure it- */copy_delimiter:- opt_using DELIMITERS Sconst { $$ = $3; }- | /*EMPTY*/ { $$ = "\t"; }+ /* USING DELIMITERS kept for backward compatibility. 2002-06-15 */+ opt_using DELIMITERS Sconst+ {+ $$ = makeNode(DefElem);+ $$->defname = "delimiter";+ $$->arg = (Node *)makeString($3);+ }+ | /*EMPTY*/ { $$ = NULL; };-opt_using: USING {}+opt_using:+ USING {}| /*EMPTY*/ {};-copy_null: WITH NULL_P AS Sconst { $$ = $4; }- | /*EMPTY*/ { $$ = "\\N"; }- ;/******************************************************************************| /* EMPTY */ { $$ = NIL; };-/*- * createdb_opt_item returns 2-element lists, with the first element- * being an integer code to indicate which item was specified.- */createdb_opt_item:LOCATION opt_equal Sconst{| DEFERRED| DEFINER| DELETE_P+ | DELIMITER| DELIMITERS| DOMAIN_P| DOUBLEindex 0f441290ea896f62106852b48f232de3e00a6962..c125cc79fbbd6e9d6b9d09de97f440859e1a7bc9 100644 (file)
*** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.114 2002/06/15 03:00:03 thomas Exp $+ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.115 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/{"deferred", DEFERRED},{"definer", DEFINER},{"delete", DELETE_P},+ {"delimiter", DELIMITER},{"delimiters", DELIMITERS},{"desc", DESC},{"distinct", DISTINCT},index 4e23a6d919066a3d474aa6724b7105e65b064bc1..c0f480085ccb60f9ab28157d088ac005ae0efba5 100644 (file)
*** IDENTIFICATION- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.157 2002/06/18 17:27:58 momjian Exp $+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.158 2002/06/20 16:00:43 momjian Exp $**-------------------------------------------------------------------------*/{CopyStmt *stmt = (CopyStmt *) parsetree;- if (stmt->direction != FROM)+ if (!stmt->is_from)SetQuerySnapshot();- DoCopy(stmt->relation,- stmt->binary,- stmt->oids,- (bool) (stmt->direction == FROM),- (bool) (stmt->filename == NULL),-- /*- * null filename means copy to/from stdout/stdin, rather- * than to/from a file.- */- stmt->filename,- stmt->delimiter,- stmt->null_print);+ DoCopy(stmt);}break;diff --git a/src/bin/pgaccess/doc/html/tutorial/tut_edit.html b/src/bin/pgaccess/doc/html/tutorial/tut_edit.htmlindex 8282fb9a422f23e8a7a5f21ee71967add3fccbfd..a4e75b17791aaf05c28d9310b26b95e486bbff1d 100644 (file)
Notice that there are two consecutive tildes to allow for the fact that thisparticular entry doesn't have anything in the Editor field.You can then perform a Query as follows:-COPY psyref FROM '/home/jim/newref.txt' USING DELIMITERS+COPY psyref FROM '/home/jim/newref.txt' WITH DELIMITER'~';This will read the records from newref.txt and insert them into thetable psyref. See the PostgreSQL documentation under the headingsindex eaf77a3ccab1e7b5225764b03ce9bf244c563369..88dd77e255b34c431b4d5df558c8c429839bce0c 100644 (file)
" {} "COPY \[ BINARY \] table \[ WITH OIDS \]FROM { 'filename' | stdin }- \[ USING DELIMITERS 'delimiter' \]+ \[ WITH DELIMITER 'delimiter' \]COPY \[ BINARY \] table \[ WITH OIDS \]TO { 'filename' | stdout }- \[ USING DELIMITERS 'delimiter' \]+ \[ WITH DELIMITER 'delimiter' \]" {code} "Inputs" {bold} "" {} "Usage" {bold} "The following example copies a table to standard output, using a vertical bar \(\"|\"\) as the field delimiter:-COPY country TO stdout USING DELIMITERS '|';+COPY country TO stdout WITH DELIMITER '|';To copy data from a Unix file into a table \"country\":COPY country FROM '/usr1/proj/bray/sql/country_data';@@ -93,13 +93,12 @@ The format for each instance in the file is as follows. Note that this format muThe " {} "BINARY" {bold} " keyword will force all data to be stored/read as binary objects rather than as text. It is somewhat faster than the normal copy command, but is not generally portable, and the files \generated are somewhat larger, although this factor is highly dependent on the data itself. By default, a text copy uses a tab \-\(\"\\t\"\) character as a delimiter. The delimiter may also be changed to any other single character with the keyword phrase USING DELIMITERS. Characters in data fields which happen to match the delimiter character will be quoted.+\(\"\\t\"\) character as a delimiter. The delimiter may also be changed to any other single character with the keyword phrase WITH DELIMITER. Characters in data fields which happen to match the delimiter character will be quoted.You must have select access on any table whose values are read by " {} "COPY" {bold} ", and either insert or update access to a table into which values are being inserted by \" {} "COPY" {bold} ". The backend also needs appropriate Unix permissions for any file read or written by \" {} "COPY" {bold} ".-The keyword phrase " {} "USING DELIMITERS" {bold} " specifies a single character to be used for all delimiters between columns. If multiple characters are specified in the delimiter string, only the first \-character is used.+The keyword phrase " {} "WITH DELIMITER" {bold} " specifies a single character to be used for all delimiters between columns.Tip: Do not confuse " {} "COPY" {bold} " with the psql instruction \\copy. "index 781989cc7b4d82fa7b662168cb4d5a26797d4430..5021d021db8247e1c61442eac1302ad05b2a5923 100644 (file)
if {$PgAcVar(impexp,delimiter)==""} {set sup ""} else {+ # now we use WITH DELIMITER, but keep old syntax for+ # backward compatibility. 2002-06-15set sup " USING DELIMITERS '$PgAcVar(impexp,delimiter)'"}if {[.pgaw:ImportExport.expbtn cget -text]=="Import"} {diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.cindex fb07b872795a3fc3ac653a1523b809d17a8159f1..32f875db84de6000b701ed691f328b0ddee8ce16 100644 (file)
--- a/src/bin/psql/copy.c+++ b/src/bin/psql/copy.c** Copyright 2000 by PostgreSQL Global Development Group*- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.22 2002/04/24 21:00:10 petere Exp $+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.23 2002/06/20 16:00:44 momjian Exp $*/#include "postgres_fe.h"#include "copy.h"* parse_slash_copy* -- parses \copy command line*- * Accepted syntax: \copy [binary] table|"table" [with oids] from|to filename|'filename' [ using delimiters ''] [ with null as 'string' ]+ * Accepted syntax: \copy table|"table" [with oids] from|to filename|'filename' [with ] [ oids ] [ delimiter ''] [ null as 'string' ]* (binary is not here yet)*+ * Old syntax for backward compatibility: (2002-06-19):+ * \copy table|"table" [with oids] from|to filename|'filename' [ using delimiters ''] [ with null as 'string' ] + ** returns a malloc'ed structure with the options, or NULL on parsing error*/error = true;else{+ /* Allows old COPY syntax for backward compatibility 2002-06-19 */if (strcasecmp(token, "with") == 0){token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);if (token){+ /* Allows old COPY syntax for backward compatibility 2002-06-19 */if (strcasecmp(token, "using") == 0){token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);- if (!token || strcasecmp(token, "delimiters") != 0)- error = true;- else+ if (token && strcasecmp(token, "delimiters") == 0){token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);if (token)elseerror = true;}+ else+ error = true;}+ }+ }- if (!error && token)+ if (!error && token)+ {+ if (strcasecmp(token, "with") == 0)+ {+ while (!error && (token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding))){- if (strcasecmp(token, "with") == 0)+ if (strcasecmp(token, "delimiter") == 0){- token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);- if (!token || strcasecmp(token, "null") != 0)+ token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);+ if (token && strcasecmp(token, "as") == 0)+ token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);+ if (token)+ result->delim = xstrdup(token);+ elseerror = true;+ }+ else if (strcasecmp(token, "null") == 0)+ {+ token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);+ if (token && strcasecmp(token, "as") == 0)+ token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);+ if (token)+ result->null = xstrdup(token);else- {- token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);- if (!token || strcasecmp(token, "as") != 0)- error = true;- else- {- token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding);- if (token)- result->null = xstrdup(token);- }- }+ error = true;}- else- error = true;+ else error = true;}}+ else error = true;}free(line);appendPQExpBuffer(&query, "BINARY ");appendPQExpBuffer(&query, "\"%s\" ", options->table);+ /* Uses old COPY syntax for backward compatibility 2002-06-19 */if (options->oids)appendPQExpBuffer(&query, "WITH OIDS ");appendPQExpBuffer(&query, "TO STDOUT");+ /* Uses old COPY syntax for backward compatibility 2002-06-19 */if (options->delim)appendPQExpBuffer(&query, " USING DELIMITERS '%s'", options->delim);free_copy_options(options);return false;}-+result = PSQLexec(query.data);termPQExpBuffer(&query);index e0a4ecdcd4053f80755b15652d01cbc9d8eba6ea..40cbb351957b58d5752bb3b85e675ee9dcd2e3ba 100644 (file)
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group* Portions Copyright (c) 1994, Regents of the University of California*- * $Id: copy.h,v 1.17 2002/03/29 19:06:21 tgl Exp $+ * $Id: copy.h,v 1.18 2002/06/20 16:00:44 momjian Exp $**-------------------------------------------------------------------------*/#ifndef COPY_H#define COPY_H+#include "nodes/parsenodes.h"#include "nodes/primnodes.h"extern int copy_lineno;-void DoCopy(const RangeVar *relation, bool binary, bool oids,- bool from, bool pipe,- char *filename, char *delim, char *null_print);+void DoCopy(const CopyStmt *stmt);#endif /* COPY_H */index 1a99da6d4da030535de085a757df9e1d295ab7c2..c4c9f56eece9354d94c8854ec19a87fe848c40b0 100644 (file)
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group* Portions Copyright (c) 1994, Regents of the University of California*- * $Id: dbcommands.h,v 1.22 2002/06/18 17:27:58 momjian Exp $+ * $Id: dbcommands.h,v 1.23 2002/06/20 16:00:44 momjian Exp $**-------------------------------------------------------------------------*/#include-extern void createdb(CreatedbStmt *stmt);+extern void createdb(const CreatedbStmt *stmt);extern void dropdb(const char *dbname);extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);index 01b90ce0285f317ff324f0176f7f1a6834392733..627c30c6441bf9b8d155440e29bc0e3c6be74f6d 100644 (file)
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group* Portions Copyright (c) 1994, Regents of the University of California*- * $Id: parsenodes.h,v 1.180 2002/06/18 17:27:58 momjian Exp $+ * $Id: parsenodes.h,v 1.181 2002/06/20 16:00:44 momjian Exp $**-------------------------------------------------------------------------*/typedef struct CopyStmt{NodeTag type;- bool binary; /* is a binary copy? */RangeVar *relation; /* the relation to copy */- bool oids; /* copy oid's? */- int direction; /* TO or FROM */+ bool is_from; /* TO or FROM */char *filename; /* if NULL, use stdin/stdout */- char *delimiter; /* delimiter character, \t by default */- char *null_print; /* how to print NULLs, `\N' by default */+ List *options; /* List of DefElem nodes */} CopyStmt;/* ----------------------diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.javaindex 3c447a88b4b50469998d20a0a78a72c25a96d017..5fba1d68c00c3770c6bb94e8f6495f084dc7ce21 100644 (file)
/** This class provides information about the database as a whole.*- * $Id: DatabaseMetaData.java,v 1.46 2002/06/11 02:55:16 barry Exp $+ * $Id: DatabaseMetaData.java,v 1.47 2002/06/20 16:00:44 momjian Exp $**Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to*/public String getSQLKeywords() throws SQLException{- return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";+ return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiter,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";}public String getNumericFunctions() throws SQLExceptiondiff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.javaindex a6130720ddbfbaa3d588489dc166edf2dbde64e4..e38f4c18e5a5372871f0627f73f989375a024e01 100644 (file)
/** This class provides information about the database as a whole.*- * $Id: DatabaseMetaData.java,v 1.55 2002/06/11 02:55:16 barry Exp $+ * $Id: DatabaseMetaData.java,v 1.56 2002/06/20 16:00:44 momjian Exp $**Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt topublic String getSQLKeywords() throws SQLException{if (Driver.logDebug) Driver.debug("getSQLKeyWords");- return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";+ return "abort,acl,add,aggregate,append,archive,arch_store,backward,binary,change,cluster,copy,database,delimiter,delimiters,do,extend,explain,forward,heavy,index,inherits,isnull,light,listen,load,merge,nothing,notify,notnull,oids,purge,rename,replace,retrieve,returns,rule,recipe,setof,stdin,stdout,store,vacuum,verbose,version";}public String getNumericFunctions() throws SQLExceptiondiff --git a/src/test/locale/de_DE.ISO8859-1/test-de-upper.sql.in b/src/test/locale/de_DE.ISO8859-1/test-de-upper.sql.inindex 5b2b32750e797ee93fdc929d071ec5443fac61f1..5149f8cd672b62c75b8367bbd9e4af0abc01d388 100644 (file)
-COPY wordlist FROM stdin USING DELIMITERS '|';+COPY wordlist FROM stdin WITH DELIMITER '|';AAA |ÄÄÄAAAAa |ÄÄÄÄäBBBB |BBBBdiff --git a/src/test/locale/de_DE.ISO8859-1/test-de.sql.in b/src/test/locale/de_DE.ISO8859-1/test-de.sql.inindex c0b0dbd4952ae6484c62376f3544d286b775cfb8..7108d0290ef33b55e6bbfd0eaef55bb668823fbc 100644 (file)
-COPY wordlist FROM stdin USING DELIMITERS '|';+COPY wordlist FROM stdin WITH DELIMITER '|';AAA |ÄÄÄAAAAa |ÄÄÄÄäBBBB |BBBBdiff --git a/src/test/locale/gr_GR.ISO8859-7/test-gr.sql.in b/src/test/locale/gr_GR.ISO8859-7/test-gr.sql.inindex 8cb638882e03f75c5e44230f99cb276ec6d9085d..781f4efcadd86af71f90449fc5e8840000f928df 100644 (file)
-COPY usastates FROM stdin USING DELIMITERS '|';+COPY usastates FROM stdin WITH DELIMITER '|';AK|Alaska |ÁëÜóêáWA|Washington |ÃïõüóéíãêôïíOR|Oregon |Ïñåãêïíindex 784d440d2f34170d8692ee44f31715eaa31d524c..6be83923bee1c496240e96a9360a0329719a14f4 100644 (file)
-COPY usastates FROM stdin USING DELIMITERS '|';+COPY usastates FROM stdin WITH DELIMITER '|';AK|Alaska |áÌÑÓËÁWA|Washington |÷ÁÛÉÎÇÔÏÎOR|Oregon |ïÒÅÇÏÎdiff --git a/src/test/locale/koi8-to-win1251/test-koi8.sql.in b/src/test/locale/koi8-to-win1251/test-koi8.sql.inindex 2a5e8175f5f2b5e729032adefb765c25fa0f1e0f..244e495176a12158058e76cfc712d5c57066ca9c 100644 (file)
-COPY usastates FROM stdin USING DELIMITERS '|';+COPY usastates FROM stdin WITH DELIMITER '|';AK|Alaska |ÀëÿñêàWA|Washington |ÂàøèíãòîíOR|Oregon |Îðåãîí