> > Anyway, my feeling about it is that \copy parsing is a huge hack > right now, and I'd rather see it become less of a hack, that is > more like other psql commands, instead of getting even hackier. >
I wasn't as horrified as Tom, but it did have the feeling of it solving half the problem. We can already do this COPY (SELECT :foo FROM :bar WHERE :condition) TO STDOUT \g :"myfilename" So it seems that what we need is a good way to pipe local data to a standard COPY command, which is then free to use the existing variable interpolations. If we could do this: COPY :"myschema".:"mytable" FROM STDIN \g < :"myfilename" that would fit our patterns most cleanly, but we would probably create a parsing hassle for ourselves if we ever wanted to mix pipe-to with pipe-from. It would also require checking on every command, when uploaded \copy commands make up a very small percentage of commands issued. So I don't think there's a good way around the asymmetry of COPY TO being a regular \g-able command, whereas COPY FROM will always require some other send-command. Perhaps we create a new command \copyfrom: COPY :"myschema".:"mytable" :options FROM STDIN \copyfrom :"myfilename" COPY :"myschema".:"mytable" :options FROM STDIN \copyfrom :"my_complex_command" | If we had something like that we might be able to replace all existing uses of \copy.