pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: marc ratun <marc_ratun@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: INSERT INTO VIEW - Replacement
Date: Tue, 09 Nov 2004 10:41:54 +0000
Message-ID: <BAY13-F1881TbdkSmLA000003ac@hotmail.com> (raw)

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/




Message-ID: <BAY13-F1881TbdkSmLA000003ac@hotmail.com>
Permalink:  ../BAY13-F1881TbdkSmLA000003ac@hotmail.com/
Also on:    postgresql.org/message-id/BAY13-F1881TbdkSmLA000003ac@hotmail.com

 · 

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: marc_ratun@hotmail.com
  Subject: Re: INSERT INTO VIEW - Replacement
  In-Reply-To: <BAY13-F1881TbdkSmLA000003ac@hotmail.com>

* 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