chickadee » postgresql » with-output-to-copy-query

with-output-to-copy-query THUNK CONNECTION QUERY #!rest PARAMSprocedure
(with-output-to-copy-query* THUNK CONNECTION QUERY [PARAMS] [format: FORMAT] [raw: RAW?])procedure

Call THUNK with CURRENT-OUTPUT-PORT parameterized to a port that writes COPY FROM STDIN data to the database connection CONN for QUERY.

Returns the final result of THUNK.

The starred and nonstarred version are analogous to query and query*.

(use postgresql)

(with-output-to-copy-query
  (lambda () (print "one\t1") (print "two\t2") "That's a wrap")
  conn "COPY my_table (textcol, numbercol) FROM STDIN")
 => "That's a wrap"