chickadee » postgresql » copy-query-map

copy-query-map PROC CONNECTION #!rest PARAMSprocedure
(copy-query*-map PROC CONNECTION [PARAMS] [format: FORMAT] [raw: RAW?])procedure

Maps COPY TO STDOUT output rows from QUERY to lists by calling PROC on each data row returned by the server. If the QUERY asked for binary data, the data supplied to PROC will be in blob form. Otherwise, the data will be provided as strings.

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

(import postgresql (chicken string))

(let ((conn (connect '((dbname . test)))))
   (copy-map (lambda (x) (apply + (map string->number (string-split x))))
             conn "COPY (SELECT 1, 100 UNION SELECT 2, 200) TO STDOUT"))
 => (101 202)