Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A3E631337990 for ; Tue, 16 Nov 2010 01:56:54 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 02734-09 for ; Tue, 16 Nov 2010 05:56:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id 26E611335B36 for ; Tue, 16 Nov 2010 01:56:46 -0400 (AST) Received: (qmail invoked by alias); 16 Nov 2010 05:56:45 -0000 Received: from mue-88-130-4-055.dsl.tropolys.de (EHLO [192.168.0.113]) [88.130.4.55] by mail.gmx.net (mp062) with SMTP; 16 Nov 2010 06:56:45 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX19t3zEpYAltx9XHTZLPvj3z9H9KcG1UP8TF1fT/4m SEc03nyMIcTkwv Message-ID: <4CE21D4A.4070200@gmx.net> Date: Tue, 16 Nov 2010 06:57:30 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: multi table import from 1 denormalized source table Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/31 X-Sequence-Number: 34769 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?