Re: COPY IN as SELECT target

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY IN as SELECT target
Date: 2009-12-17 18:43:20
Message-ID: 603c8f070912171043l3b730f02w17632c79b2431a6f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Dec 17, 2009 at 1:37 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>> Tom Lane wrote:
>>> The problem with COPY FROM is that it hard-wires a decision that there
>>> is one and only one possible result format, which I think we pretty
>>> much proved already is the wrong thing.  I'm not thrilled with "RETURNING
>>> ARRAY" either, but we need to leave ourselves wiggle room to have more
>>> than one result format from the same source file.
>
>> Well, we could have "RETURNING type-expression" with  "text[]" supported
>> for the first iteration.
>
>> In answer to Heiki's argument, what I wanted was exactly to return an
>> array of text for each row. Whatever we have needs to be able to handle
>> to possibility of ragged input (see previous discussion) so we can't tie
>> it down too tightly.
>
> I think that there are two likely possibilities for the result format:
>
> * "Raw" data after just the de-escaping and column separation steps.
> Array of text is probably the right thing here, at least for a text COPY
> (doesn't seem to cover the binary case though).
>
> * The data converted to some specified row type.

Agreed.

> "RETURNING type-expression" is probably not good since it looks more
> like the second case than the first --- and in fact it could be outright
> ambiguous, what if your data actually is one column that is a text
> array?
>
> If we're willing to assume these are the *only* possibilities then we
> could use "COPY FROM ..." for the first and "COPY RETURNING type-list
> FROM ..." for the second.  I'm a bit uncomfortable with that assumption
> though; it seems likely that we'll want to shoehorn in some more
> alternatives later.  (Like, what about the binary case?)

You might want to specify column names as well as well as types, in
this second case.

...Robert

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2009-12-17 18:50:08 Re: determine snapshot after obtaining locks for first statement
Previous Message Robert Haas 2009-12-17 18:41:38 Re: determine snapshot after obtaining locks for first statement