Re: COPY IN as SELECT target

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY IN as SELECT target
Date: 2009-12-17 17:42:18
Message-ID: 603c8f070912170942u1dd2534bxd4f9b6e2836d53e3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Dec 17, 2009 at 12:38 PM, David Fetter <david(at)fetter(dot)org> wrote:
> On Thu, Dec 17, 2009 at 12:28:50PM -0500, Robert Haas wrote:
>> On Thu, Dec 17, 2009 at 12:23 PM, Heikki Linnakangas
>> <heikki(dot)linnakangas(at)enterprisedb(dot)com> wrote:
>> > How about just COPY FROM? As in
>> >
>> > SELECT t[5] as a, 3*(t[3]::numeric) as b FROM (COPY FROM STDIN
>> > CSV) as t
>>
>> I had the same thought.  Though it would also be nice to allow
>> something like:
>>
>> COPY (type1, type2, type3, type4) FROM STDIN CSV
>>
>> ...which is obviously going to create a horrible parser problem if
>> you actually tried to use that syntax.
>
> How about using the CTE syntax?

I'm not sure what you're suggesting exactly, but the problem with the
syntax I suggested is that COPY (...) TO <whatever> expects the "..."
part to be a subselect. You can't make COPY (...) FROM have something
in there other than a subselect, because the parser can't fast-forward
and look at the word FROM and then go back and decide how to parse the
parenthesized stuff. That's almost magic in the general case. You'd
have to stick a keyword in there before the opening parentheses.

...Robert

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-12-17 17:42:45 Re: COPY IN as SELECT target
Previous Message Tom Lane 2009-12-17 17:39:58 Re: determine snapshot after obtaining locks for first statement