Re: instead of trigger in pg

From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: J Crypter <jcrypter(at)yahoo(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: instead of trigger in pg
Date: 2005-12-28 16:03:32
Message-ID: c2d9e70e0512280803hdb76fedl5cafba5170efad7a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 12/28/05, J Crypter <jcrypter(at)yahoo(dot)de> wrote:
> 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.
>

postgres uses rules for this situation... and yes there are INSTEAD OF rules...

> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-12-28 17:03:57 Re: Cursors and recursion
Previous Message Tom Lane 2005-12-28 15:48:25 Re: Cursors and recursion