From: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Question on imports with foreign keys |
Date: | 2011-12-10 23:01:11 |
Message-ID: | jc0obn$521$1@reversiblemaps.ath.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 2011-12-08, Andreas <maps(dot)on(at)gmx(dot)net> wrote:
> Hi,
>
> suppose you need to import a csv with standard ciolums like name,
> adress, phone, ... and some additional text columns that need to be
> split off into referenced tables.
...
> How is the easiest way to to find the customer.id of the new customers
> so I can insert the projectinfos?
create table tmp.customer (id integer, name text, addr text)
copy tmp.customer ( id,name,addr ) from stdin ;
...
alter table tmp.customer add column new_id integer default nextval('customer_id.seq'::regclass);
(here the default is the same default that the customer table uses for
its id.)
now you can use "insert ... select ..." to insert these new records
explicitly using new_id to fill the id column of the customer table.
iport the other csv data into similar tables also
and use join on the old id in tmp.customer to get the new id for
copying the other imported tabled.
--
⚂⚃ 100% natural
From | Date | Subject | |
---|---|---|---|
Next Message | Misa Simic | 2011-12-12 09:36:24 | Re: Subselects to Joins? Or: how to design phone calls database |
Previous Message | Viktor Bojović | 2011-12-10 22:51:44 | Re: Subselects to Joins? Or: how to design phone calls database |