> I simply want to increment a column named 'id', which contains a serial
> number, in table 'b' every time an insert is performed in a table 'a'. I
> have tried the psql \h command and found the create trigger command,
though
> it wasn't a great deal of help to this beginner.
> Unfortunately, I have found no ANSI SQL documentation to show how to do
> this, and the docs I did find were confusing, or DBMS specific. Also,
there
> is no standard SQL list to my surprise :(
> Could someone explain how to do this? Does it require C functions, or can
> you use SQL procedures?
What about using currval and nextval or sequences?
Granted it would involve you having to to do 2 queries - one to update table
a and one to update table b.
If you create a sequence and then for the id in b update it using
INSERT INTO b (id) VALUES (nextval('tableb_seq'))
Looking at the syntax for trigger, you be after somethng like
CREATE TRIGGER triggername AFTER INSERT ON tablea FOR EACH ROW EXECUTE
PROCEDURE updateb()
then you'd have to create a function to actually do it
CREATE FUNCTION updateb () RETURNS opaque AS '
BEGIN
INSERT INTO tableb (id) VALES (nextval('tableb_id_seq'))
END;
' LANGUAGE 'plpgsql';
Create the function first...
Hmm or maybe a rule would work. I don't know much about them but it could go
something like
CREATE RULE updateb AS ON INSERT TO tablea
DO INSERT INTO tableb (id) VALES (nextval('tableb_id_seq'))
Cheers,
Graeme
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text