COPY can also be used without files. The command can, for
example, use the same input and output locations used by psql.
The special name stdin represents the psql
input, and stdout represents the psql
output. Figure shows how you can
use stdin to supply COPY input directly from your
keyboard.
test=> COPY copytest FROM stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
test> 3 77.43 coffee f
test> \.
test=> COPY copytest TO stdout;
1 23.99 fresh spring water t
2 55.23 bottled soda t
3 77.43 coffee f
test=>
For clarity, text typed by the user appears in bold. The gaps in the second typed line were generated by pressing the tab key. The user typed \. to exit COPY...FROM. A COPY to stdout operation displays the COPY output on your screen, which can be useful when using psql in automated scripts.