pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas <maps.on@gmx.net>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: need help with import
Date: Thu, 16 Feb 2012 02:02:58 +0100
Message-ID: <4F3C55C2.8070005@gmx.net> (raw)

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 FROM import;
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.




view thread (5+ messages)  latest in thread

Message-ID: <4F3C55C2.8070005@gmx.net>
Permalink:  ../4F3C55C2.8070005@gmx.net/
Also on:    postgresql.org/message-id/4F3C55C2.8070005@gmx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: maps.on@gmx.net
  Subject: Re: need help with import
  In-Reply-To: <4F3C55C2.8070005@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox