Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E786D2E0366 for ; Fri, 7 Dec 2007 09:22:31 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 64741-09 for ; Fri, 7 Dec 2007 09:22:21 -0400 (AST) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id A3B6D2E0377 for ; Fri, 7 Dec 2007 09:22:28 -0400 (AST) Received: (qmail 2528 invoked by uid 0); 7 Dec 2007 13:22:26 -0000 Received: from 194.204.64.65 by www094.gmx.net with HTTP; Fri, 07 Dec 2007 14:22:26 +0100 (CET) Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Date: Fri, 07 Dec 2007 14:22:26 +0100 From: "Stefan Scheidegger" Message-ID: <20071207132226.281710@gmx.net> MIME-Version: 1.0 Subject: INSERT INTO relational tables To: pgsql-sql@postgresql.org X-Authenticated: #1368470 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX1+YTDszmQmYWCpde73UB2Qu1+pnYuD6IS5/nnqwzD RblwYoQIuKG08pSrjDS06D/bhotDJ42FvWEQ== X-GMX-UID: IH9sdn4GbUk7GqDSJmgnWgpsZ2hlN4pV X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200712/23 X-Sequence-Number: 29715 Hi all I'm new to SQL and I'm facing a problem I can't find any information about (google, forums). By now I wonder if I understood something wrong about relational DBs. An example to explain my Problem: Lets say I have a table containing information about the customer (name, address, ...) and about his order (pieces, product-name, price). Because one customer can order several products I split the table into two relational tables to prevent redundancy: tbl_customer (cust_id, cust_name, cust_address) and tbl_order (ord_pieces, ord_productname, ord_price, ord_customer REFERENCES tbl_customer(cust_id)) Now I want to insert several new customers with several orders each at once. If I had all information in one table, this would be easy with something like: INSERT INTO tbl_customerorders (name, address, pieces, porductname, price) VALUES ('MR. X', '1st street', 3, 't-shirts', 30), ('MR. X', '1st street', 5, 'books', 50), ('MRS. Y', '2nd street', 1, 't-shirt', 10),... But how can I do this in one query if I split the table? I can add one new customer, get his ID with curval() and then add his orders. But this won’t work if I want to add several customers at once. To read this information I can do a query with the argument WHERE cust_id=ord_customer. I can create a VIEW doing this so I can read the data as if it was stored in only one table. But is there in posgres/sql an abstraction-layer that allows me to insert as if the information was stored in one table? (Something like a VIEW that provides INSERT, UPDATE, … and automatically inserts the referenced ID.) Thanks for any help! Stefan -- Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger