Next: , Previous: , Up: The (database postgres*) Modules   [Contents][Index]


5 Procedures for Copying Data

As of PostgreSQL 7.4, you can send arbitrarily-sized chunks of data after issuing the COPY <table> FROM STDIN command. Also, both send and receive (with the COPY <table> TO STDOUT command) paths can be performed asynchronously.

Procedure: pg-put-copy-data conn data

Send on conn the data (a string). Return one if ok; zero if the server is in nonblocking mode and the attempt would block; and -1 if an error occurred.

Procedure: pg-put-copy-end conn [errmsg]

Send an end-of-data indication over conn. Optional arg errmsg is a string, which if present, forces the COPY operation to fail with errmsg as the error message. Return one if ok; zero if the server is in nonblocking mode and the attempt would block; and -1 if an error occurred.

Procedure: pg-get-copy-data conn port [async?]

Get a line of COPY data from conn, writing it to output port. If port is a pair, construct a new string and set its CAR to the new string. Optional arg async? non-#f means don’t block if there is no data available yet. Return the number of data bytes in the row (always greater than zero); zero to mean the COPY is still in progress and no data is yet available; -1 to mean the COPY is done; or -2 to mean an error occurred.

Although not readily apparent, another form of data copying is formatted output, which is supported by Guile-PG via the pg-print procedure and the accompanying pg-make-print-options. Together these loosely mimic the PQprint functionality provided by libpq.

Procedure: pg-make-print-options spec

Return a print options object created from spec, suitable for use with pg-print. spec is a list of elements, each either a flag (symbol) or a key-value pair (with the key being a symbol). Recognized flags:

  • header — Print output field headings and row count.
  • align — Fill align the fields.
  • standard — Old brain-dead format.
  • html3 — Output HTML tables.
  • expanded — Expand tables.

To specify a disabled flag, use no-FLAG, e.g., no-header. Recognized keys:

  • field-sep — String specifying field separator.
  • table-opt — String specifying HTML table attributes.
  • caption — String specifying caption to use in HTML table.
  • field-names — List of replacement field names, each a string.
Procedure: pg-print result [options]

Display result on the current output port. Optional second arg options is an object returned by pg-make-print-options that specifies various parameters of the output format.


Next: Procedures for Managing Large Objects, Previous: Procedures for Retrieving Data, Up: The (database postgres*) Modules   [Contents][Index]