On 15 Oct. 2016 04:56, "Corey Huinker" <corey.huin...@gmail.com> wrote:
> I would like to make COPY itself a SRF. That's a bit beyond my capabilities, so if that is the route we want to go, I will need help. > > The syntax would probably look like this (new bits in bold): > >> WITH my_copy AS ( >> COPY FROM 'example.csv' TO RESULT SET(c1 text, c2 integer, dummy1 text, dummy2 text, c5 date) WITH (FORMAT CSV) >> RETURNING c1, c2, c3 >> ) Strong -1 from me on this approach. Our CTE implementation materializes everything so this is no better than COPYing to a temp table. Not unless you plan to fix that (and figure out the backward compatibility issues since the bug is documented as a feature) or implement RETURNING in subqueries... I'd go for the function.