From: J Crypter <jcrypter@yahoo.de>
To: pgsql-sql@postgresql.org
Subject: instead of trigger in pg
Date: Wed, 28 Dec 2005 16:28:23 +0100 (CET)
Message-ID: <20051228152823.2471.qmail@web26001.mail.ukl.yahoo.com> (raw)
Hi,
I would like to implement a 1:n relation between two
tables.
An auto-generated number should be used as primary key
which connects both tables.
Example:
table 1:
name | number (prim_key)
table 2:
country | number_table1 (foreign key)
View:
number_table1 | name | country
I would like to insert into both tables in one step.
"Insert into view (name,
country)values('name','country');"
Oracle supports an instead-of-trigger but Postgres
doesn't do this.
CREATE or replace FUNCTION insertInto() RETURNS
trigger AS '
BEGIN
insert into table1(name)values(NEW.name);
insert into
table2(number,country)values(NEW.number,NEW.country);
RETURN NEW;
END;
' LANGUAGE plpgsql;
CREATE TRIGGER insert_TR BEFORE INSERT OR UPDATE ON
view
FOR EACH ROW EXECUTE PROCEDURE insertInto();
I would like to implement something like this but I
don't know how to do.
Thank you for you help!
Jakob
___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
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: jcrypter@yahoo.de
Subject: Re: instead of trigger in pg
In-Reply-To: <20051228152823.2471.qmail@web26001.mail.ukl.yahoo.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