Dan Armbrust wrote:
Is there a better way to do this? Is there a flag I could specify for psql that would cause it to output INSERT or COPY statements as a result of a query - select * from foo where terminologyId=foo? Then I could just have 15 select statements batched up in a file, and pipe the output into a new file.
It's easy enough to get psql to output tab-separated columns to a file from its query (see the various backslash formatting commands and \o). Spit out the 15 different files you want to /tmp, then use a script with COPY ... FROM /tmp/file1 etc.
If you use COPY the files need to be readable by the backend process, otherwise look into \copy in a psql script.
If it gets much more complicated, I knock up a short Perl script. Others probably prefer Python or Ruby.
-- Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster