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 a sequence. I also tried a trigger AFTER
insert FOR EACH ROW
, but result was the same. Any way to work this out?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…