From: | Josh Berkus <josh(at)agliodbs(dot)com> |
---|---|
To: | Michiel Lange <michiel(at)minas(dot)demon(dot)nl>, pgsql-sql(at)postgresql(dot)org |
Cc: | Michiel Lange <michiel(at)minas(dot)demon(dot)nl>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: trying to learn plpqsql... so please forgive.. |
Date: | 2002-11-20 22:27:41 |
Message-ID: | 200211201427.41550.josh@agliodbs.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Michiel,
> And this function:
> CREATE FUNCTION add_cust() RETURNS INT4 AS ' -- SERIAL data type is really
> an INT4 (and some more).
> BEGIN
> RETURN NEW.my_key;
> END;
> ' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER add_cust BEFORE INSERT ON mytable
> FOR EACH ROW EXECUTE PROCEDURE add_cust();
>
> Ok, now I know it won't work... the idea was to use this with PHP in a
> webclient interface where the customer could give some information about
> him/herself and then would be registered with the customer number generated
> by the SERIAL type.
> Would it work if I did a CREATE TRIGGER add_cust AFTER INSERT... ? (mention
> the AFTER instead of BEFORE)
No, you can't return a value to the client from a Trigger. Not ever.
Triggers modify data, and they can log stuff, but they can't return values to
the calling interface.
Now, what you could do is replace the whole insert with a function, doing:
SELECT add_cust( name, address, phone, credit_card);
Which does the inserting and returns the new id to the client. This is a
solution I frequently use in my web apps.
-Josh Berkus
From | Date | Subject | |
---|---|---|---|
Next Message | Medi Montaseri | 2002-11-20 22:47:39 | Re: Closing inactive connections OR user connections limits |
Previous Message | Michiel Lange | 2002-11-20 22:14:16 | Re: trying to learn plpqsql... so please forgive.. |