X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CF09C3A2B23 for ; Tue, 9 Nov 2004 10:42:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61921-01 for ; Tue, 9 Nov 2004 10:42:02 +0000 (GMT) Received: from hotmail.com (bay13-f18.bay13.hotmail.com [64.4.31.18]) by svr1.postgresql.org (Postfix) with ESMTP id DA5AF3A23D0 for ; Tue, 9 Nov 2004 10:42:04 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 9 Nov 2004 02:42:03 -0800 Received: from 213.20.171.182 by by13fd.bay13.hotmail.msn.com with HTTP; Tue, 09 Nov 2004 10:41:54 GMT X-Originating-IP: [213.20.171.182] X-Originating-Email: [marc_ratun@hotmail.com] X-Sender: marc_ratun@hotmail.com From: "marc ratun" To: pgsql-sql@postgresql.org Subject: INSERT INTO VIEW - Replacement Date: Tue, 09 Nov 2004 10:41:54 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 09 Nov 2004 10:42:03.0227 (UTC) FILETIME=[BFDFB2B0:01C4C648] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200411/78 X-Sequence-Number: 19397 Hi, I've this data model: CREATE SEQUENCE a_seq START 1; CREATE SEQUENCE b_seq START 1; CREATE TABLE a ( aid integer NOT NULL PRIMARY KEY, aval character varying (255) NOT NULL ); INSERT INTO a (select nextval('a_seq'),'a1'); INSERT INTO a (select nextval('a_seq'),'a2'); CREATE TABLE b ( bid integer NOT NULL PRIMARY KEY, bval character varying (255) NOT NULL ); INSERT INTO b (select nextval('b_seq'),'b1'); INSERT INTO b (select nextval('b_seq'),'b2'); CREATE TABLE c ( cid integer NOT NULL, aid integer REFERENCES a (aid), bid integer REFERENCES b (bid), cval character varying (255) NOT NULL, PRIMARY KEY (cid) ); CREATE VIEW myview AS SELECT cid,aval,bval,cval FROM c INNER JOIN a ON (a.aid=c.aid) INNER JOIN b ON (b.bid=c.bid); Now I'd like to insert a row into "c" and if necessary simultaneously create the referenced rows in the referenced tables: INSERT INTO myview VALUES (10,'a3','b1','c1'); (Here a row in "a" with aval 'a3' should be created) INSERT INTO myview VALUES (20,'a1','b2','c2'); (here a row in "a" with aval 'a1' should not be created but referenced.) (Same for "b"). "Insert into view" would't work, how could I do my INSERTS efficiently in postgres without having eache time an extra query which asks whether there already is a row in "a" which could be referenced to. ie mache ich das Thanks! Marc _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.com/