From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | "Demel, Jeff" <Jeff(dot)Demel(at)JavelinDirect(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: COPY FROM - force a value |
Date: | 2007-02-08 19:21:49 |
Message-ID: | 20070208192149.GY24069@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Demel, Jeff wrote:
> Is there a way to force a value when you're doing a COPY FROM, importing
> a file into a table?
>
> Here's my query as it is now:
>
> COPY filetable (value1, value2, value3, value4, forcevalue1,
> forcevalue2)
> FROM 'C:\\InsertFiles\\thisfile.txt'
> WITH DELIMITER AS ' '
> ;
>
> The file only contains data for values 1 through 4. I'd like to insert
> values for the last two fields. This is what I had in mind, which
> doesn't work:
>
> COPY filetable (value1, value2, value3, value4, forcevalue1,
> forcevalue2)
> FROM 'C:\\InsertFiles\\thisfile.txt'
> WITH DELIMITER AS ' ',
> forcevalue1 = 1,
> forcevalue2 = 'this value'
> ;
I'd try setting a DEFAULT for those two columns using ALTER TABLE, then
the COPY FROM call excluding those columns, then removing the DEFAULT.
If you do it in a transaction block, no other transaction can be
molested by the default values, though they will be blocked of the table
during that transaction.
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2007-02-08 19:30:39 | Re: Differentiate Between Zero-Length String and NULLColumn Values |
Previous Message | David Klugmann | 2007-02-08 19:18:56 | unsubscribe |