Bradley Kieser
2004-09-22 13:21:42 UTC
I have a rule on a view that needs to insert into two tables. The one
table has a serial ID as its unique key. The second table links to the
first one in one of its columns.
I would prefer to keep this as a rule-based solution and not have to
write a function as I hope to relicate the solution across many views.
I need to either be able to select nextval() the ID for the first table
and somehow store this in the rule (but I don't see that rules support
variables) or I need to somehow obtain the OID from the first insert in
order to select back the ID that was assigned during the insert and pass
it to the second insert (trivial to do as the second insert is then
simply a select-based insert, provided that I know the OID of that first
row!).
Does anyone know how to do this?
Here is the problem graphically:
Table A:
id serial
xxx text
[etc]
Table B:
col1,
col2,
col3 foreign key to id in table A
I need to insert a new record into both the above where b.col3
references a.id
Thanks,
Brad
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ***@postgresql.org)
table has a serial ID as its unique key. The second table links to the
first one in one of its columns.
I would prefer to keep this as a rule-based solution and not have to
write a function as I hope to relicate the solution across many views.
I need to either be able to select nextval() the ID for the first table
and somehow store this in the rule (but I don't see that rules support
variables) or I need to somehow obtain the OID from the first insert in
order to select back the ID that was assigned during the insert and pass
it to the second insert (trivial to do as the second insert is then
simply a select-based insert, provided that I know the OID of that first
row!).
Does anyone know how to do this?
Here is the problem graphically:
Table A:
id serial
xxx text
[etc]
Table B:
col1,
col2,
col3 foreign key to id in table A
I need to insert a new record into both the above where b.col3
references a.id
Thanks,
Brad
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ***@postgresql.org)