samedi 20 décembre 2014

insert inserted id to another table


Here's the scenario:



create table a (
id serial primary key,
val text
);

create table b (
id serial primary key,
a_id integer references a(id)
);

create rule a_inserted as on insert to a do also insert into b (a_id) values (new.id);


I'm trying to create a record in b referencing to a on insertion to a table, but what I get is that new.id is null, as it's automatically generated from sequence. I also tried it with trigger, that is launched AFTER insert FOR EACH ROW on a table, but result was the same. Any way to work this out?





Aucun commentaire:

Enregistrer un commentaire