|The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 478 pages
RRP £14.95 ($19.95)
Sales of this book support the PostgreSQL project! Get a printed copy>>>
1.8 Functions Associated with the COPY Command
COPY command in
PostgreSQL has options to read from or write
to the network connection used by libpq.
The functions described in this section allow applications to take
advantage of this capability by supplying or consuming copied data.
The overall process is that the application first issues the SQL
COPY command via
PQexec or one
of the equivalent functions. The response to this (if there is no
error in the command) will be a
PGresult object bearing
a status code of
PGRES_COPY_IN (depending on the specified copy
direction). The application should then use the functions of this
section to receive or transmit data rows. When the data transfer is
PGresult object is returned to indicate
success or failure of the transfer. Its status will be
PGRES_COMMAND_OK for success or
PGRES_FATAL_ERROR if some problem was encountered.
At this point further SQL commands can be issued via
PQexec. (It is not possible to execute other SQL
commands using the same connection while the
operation is in progress.)
COPY command is issued via
PQexec in a string that could contain additional
commands, the application must continue fetching results via
PQgetResult after completing the
sequence. Only when
NULL is it certain that the
command string is done and it is safe to issue more commands.
The functions of this section should be executed only after obtaining
a result status of
PGresult object bearing one of these status values
carries some additional data about the
that is starting. This additional data is available using functions
that are also used in connection with query results:
- Returns the number of columns (fields) to be copied.
0 indicates the overall copy format is textual (rows separated by
newlines, columns separated by separator characters, etc). 1
indicates the overall copy format is binary. See
COPYfor more information.
Returns the format code (0 for text, 1 for binary) associated with
each column of the copy operation. The per-column format codes
will always be zero when the overall copy format is textual, but
the binary format can support both text and binary columns.
(However, as of the current implementation of
COPY, only binary columns appear in a binary copy; so the per-column formats always match the overall format at present.)
Note: These additional data values are only available when using protocol 3.0. When using protocol 2.0, all these functions will return 0.
|ISBN 9781906966065||The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide||See the print edition|