Add support for piping COPY to/from an external program.
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Add support for piping COPY to/from an external program. This includes backend "COPY TO/FROM PROGRAM '...'" syntax, and corresponding psql \copy syntax. Like with reading/writing files, the backend version is superuser-only, and in the psql version, the program is run in the client. In the passing, the psql \copy STDIN/STDOUT syntax is subtly changed: if you the stdin/stdout is quoted, it's now interpreted as a filename. For example, "\copy foo from 'stdin'" now reads from a file called 'stdin', not from standard input. Before this, there was no way to specify a filename called stdin, stdout, pstdin or pstdout. This creates a new function in pgport, wait_result_to_str(), which can be used to convert the exit status of a process, as returned by wait(3), to a human-readable string. Etsuro Fujita, reviewed by Amit Kapila.
Files
| Path | Change | +/− |
|---|---|---|
| contrib/file_fdw/file_fdw.c | modified | +3 −1 |
| doc/src/sgml/keywords.sgml | modified | +7 −0 |
| doc/src/sgml/ref/copy.sgml | modified | +45 −5 |
| doc/src/sgml/ref/psql-ref.sgml | modified | +22 −11 |
| src/backend/commands/copy.c | modified | +150 −55 |
| src/backend/nodes/copyfuncs.c | modified | +1 −0 |
| src/backend/nodes/equalfuncs.c | modified | +1 −0 |
| src/backend/parser/gram.y | modified | +36 −12 |
| src/backend/storage/file/fd.c | modified | +91 −7 |
| src/bin/psql/copy.c | modified | +107 −24 |
| src/bin/psql/stringutils.c | modified | +1 −4 |
| src/bin/psql/stringutils.h | modified | +2 −0 |
| src/include/commands/copy.h | modified | +1 −1 |
| src/include/nodes/parsenodes.h | modified | +1 −0 |
| src/include/parser/kwlist.h | modified | +1 −0 |
| src/include/port.h | modified | +3 −0 |
| src/include/storage/fd.h | modified | +4 −0 |
| src/interfaces/ecpg/preproc/ecpg.addons | modified | +1 −1 |
| src/port/exec.c | modified | +10 −27 |
| src/port/Makefile | modified | +2 −1 |
| src/port/wait_error.c | added | +92 −0 |