Re: COPY from CSV, passing in default value? - Mailing list pgsql-general

From François Beausoleil
Subject Re: COPY from CSV, passing in default value?
Date
Msg-id 5895824A-7DE9-426C-BE09-D81C1F22AFA5@teksol.info
Whole thread Raw
In response to COPY from CSV, passing in default value?  (adebarros <adebarros@gmail.com>)
List 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

pgsql-general by date:

Previous
From: Kyle Lanclos
Date:
Subject: Performance of PostgreSQL B+-tree algorithm
Next
From: Tom Lane
Date:
Subject: Re: Performance of PostgreSQL B+-tree algorithm