From: | François Beausoleil <francois(at)teksol(dot)info> |
---|---|
To: | adebarros <adebarros(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: COPY from CSV, passing in default value? |
Date: | 2012-05-14 18:36:13 |
Message-ID: | 5895824A-7DE9-426C-BE09-D81C1F22AFA5@teksol.info |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Le 2012-05-14 à 13:31, adebarros a écrit :
> However, what if I wanted to assign a default value during import to
> populate the County field? In my dreams it would be something like this
> (which does not work):
>
> COPY salaries (Town, 'County Name', Supervisor, Salary)
> FROM 'C:\salaries.csv'
> WITH (FORMAT CSV);
>
> Any ideas?
Import to a temp table, fill in the default value, then copy to the final table, something like this:
CREATE TEMPORARY TABLE salaries_import(LIKE (salaries) );
COPY salaries_import(town, supervisor, salary)
FROM '...',
WITH (format csv);
INSERT salaries(town, country, supervisor, salary)
SELECT town, 'County Name', supervisor, salary
FROM salaries_import;
Hope that helps!
François Beausoleil
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-05-14 18:49:16 | Re: Performance of PostgreSQL B+-tree algorithm |
Previous Message | Kyle Lanclos | 2012-05-14 18:10:30 | Performance of PostgreSQL B+-tree algorithm |