Re: COPY FROM - how to identify results?

From: Jaime Silvela <JSilvela(at)Bear(dot)com>
To: Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY FROM - how to identify results?
Date: 2007-04-04 12:43:44
Message-ID: 46139D80.1010202@bear.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I can't use triggers because I need a specific "my_id".
Here's the scenario: a user is browsing the web page for portfolio_id =
3, and wants to update the values. He uploads a CSV file, and I need its
entries to be tagged with portfolio_id = 3, as another user could be
uploading a CSV file for portfolio_id = 9.

As suggested by John Burger, I think the cleanest way to deal with this
is to have the CSV file COPY'd to a TEMP table, local to the user's
session, and from there inserted with INSERT INTO portfolio(field-1, ..
field-n, portfolio_id) SELECT field-1, .. field-n, 3 FROM ....;

Thank you,
Jaime

Klint Gore wrote:
> On Tue, 03 Apr 2007 12:45:54 -0400, Jaime Silvela <JSilvela(at)Bear(dot)com> wrote:
>
>> I'd like to be able to do something like
>> COPY mytable (field-1, .. field-n, id = my_id) FROM file;
>>
>
> How do you get my_id? Can you get it in a trigger? Triggers still fire
> with copy so if you can get a trigger to fill in the id column you can
> copy with just the field names.
>
> klint.
>
> +---------------------------------------+-----------------+
> : Klint Gore : "Non rhyming :
> : EMail : kg(at)kgb(dot)une(dot)edu(dot)au : slang - the :
> : Snail : A.B.R.I. : possibilities :
> : Mail University of New England : are useless" :
> : Armidale NSW 2351 Australia : L.J.J. :
> : Fax : +61 2 6772 5376 : :
> +---------------------------------------+-----------------+
>
>

***********************************************************************
Bear Stearns is not responsible for any recommendation, solicitation,
offer or agreement or any information about any transaction, customer
account or account activity contained in this communication.

Bear Stearns does not provide tax, legal or accounting advice. You
should consult your own tax, legal and accounting advisors before
engaging in any transaction. In order for Bear Stearns to comply with
Internal Revenue Service Circular 230 (if applicable), you are notified
that any discussion of U.S. federal tax issues contained or referred to
herein is not intended or written to be used, and cannot be used, for
the purpose of: (A) avoiding penalties that may be imposed under the
Internal Revenue Code; nor (B) promoting, marketing or recommending to
another party any transaction or matter addressed herein.
***********************************************************************

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-04-04 13:34:13 Re: Problem with a transaction on dump
Previous Message Jaime Silvela 2007-04-04 12:37:17 Re: COPY FROM - how to identify results?