Re: Question on imports with foreign keys

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Question on imports with foreign keys
Дата
Msg-id jc0obn$521$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Question on imports with foreign keys  (Andreas <maps.on@gmx.net>)
Список pgsql-sql
On 2011-12-08, Andreas <maps.on@gmx.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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Jasen Betts
Дата:
Сообщение: Re: conditional FROM
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: partitions versus databases