Re: need help with import

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: need help with import
Дата
Msg-id 013001ccec48$3db033e0$b9109ba0$@yahoo.com
обсуждение исходный текст
Ответ на need help with import  (Andreas <maps.on@gmx.net>)
Ответы Re: need help with import  (Andreas <maps.on@gmx.net>)
Список pgsql-sql
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Andreas
Sent: Wednesday, February 15, 2012 8:03 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] need help with import

Hi
I get CSV files to import.
Th structure is like this.
main part, sub part
Could be like this

A, a1
A, a2
A, a3
B, b1
B, b2

The database has a table for main_part and one for sub_part.
The relation needs to be n:m so there is a relation table that holds ( main_id, sub_id ).
The 2 primary keys main_part.id and sub_part.id are both serials.

Is there a way to do an import with SQL?

I can read the CSV into a temporary table and I can do a INSERT INTO main_part ( ... ) SELECT DISTINCT main columns
FROMimport; as well as a INSERT INTO sub_part ( ... ) SELECT sub columns FROM import; 

But how would I know what main_id and sub_id to insert into the n:m relation?

At first when I do the import the relation is actually 1:n.

--------------------------------------------

You will need to use the temporary table and perform multiple insert+select.

I do not understand where you are confused.  It would help to provide more meaningful sample data and/or the final
resultyou are trying to achieve.  Keep in mind any n:m setup requires three tables with the joining table usually
havingsome descriptive meaning.  Is time one of your components that you are not  showing us? 

Dave


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



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

Предыдущее
От: Andreas
Дата:
Сообщение: need help with import
Следующее
От: Andreas
Дата:
Сообщение: Re: need help with import