pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
multi table import from 1 denormalized source table
2+ messages / 2 participants
[nested] [flat]

* multi table import from 1 denormalized source table
@ 2010-11-16 05:57 Andreas <maps.on@gmx.net>
  2010-11-16 08:21 ` Re: multi table import from 1 denormalized source table Jasen Betts <jasen@xnet.co.nz>
  0 siblings, 1 reply; 2+ messages in thread

From: Andreas @ 2010-11-16 05:57 UTC (permalink / raw)
  To: pgsql-sql

Hi,

I frequently get tables from spreadsheets to import into the DB.

Usually it looks like this:
A1, A2, A3, A4,   B1, B2, B3,   with optional C1, C2,   D1, D2, ...

and there is a 1:n relation between A and B.
If provieded the C would be 1:1 to A and D 1:1 to B.

Up until now I let a VBA script order the source table by A, then scan 
the table line by line and create a new entry in the target table A* and 
fetch its serial ID everytime the script figures that A changed.
With this IDa create 1 C* and as many B*s until A changes again ... and 
of course fetch IDb to attach the D* records with a foreign key column.

Now I'm trying to get away w/o the VBA stuff.

Is there a clever way to split such denormalized sources while still 
obtaining the needed IDs to connect everything?



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: multi table import from 1 denormalized source table
  2010-11-16 05:57 multi table import from 1 denormalized source table Andreas <maps.on@gmx.net>
@ 2010-11-16 08:21 ` Jasen Betts <jasen@xnet.co.nz>
  0 siblings, 0 replies; 2+ messages in thread

From: Jasen Betts @ 2010-11-16 08:21 UTC (permalink / raw)
  To: pgsql-sql

On 2010-11-16, Andreas <maps.on@gmx.net> wrote:
> Hi,
>
> I frequently get tables from spreadsheets to import into the DB.
>
> Usually it looks like this:
> A1, A2, A3, A4,   B1, B2, B3,   with optional C1, C2,   D1, D2, ...
>
> and there is a 1:n relation between A and B.
> If provieded the C would be 1:1 to A and D 1:1 to B.
>
> Up until now I let a VBA script order the source table by A, then scan 
> the table line by line and create a new entry in the target table A* and 
> fetch its serial ID everytime the script figures that A changed.
> With this IDa create 1 C* and as many B*s until A changes again ... and 
> of course fetch IDb to attach the D* records with a foreign key column.
>
> Now I'm trying to get away w/o the VBA stuff.
>
> Is there a clever way to split such denormalized sources while still 
> obtaining the needed IDs to connect everything?

create a temporary table and put the IDS in there.

then do a select distinct to populate table B, 
do an update from to put the IDs from B into the temp table
then do a select to populate table A

etc...



-- 
⚂⚃ 100% natural



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-11-16 08:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 05:57 multi table import from 1 denormalized source table Andreas <maps.on@gmx.net>
2010-11-16 08:21 ` Jasen Betts <jasen@xnet.co.nz>

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