Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id DA839475843 for ; Wed, 20 Nov 2002 17:25:39 -0500 (EST) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 338BB474E61; Wed, 20 Nov 2002 17:25:39 -0500 (EST) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1834714; Wed, 20 Nov 2002 14:29:52 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Michiel Lange , pgsql-sql@postgresql.org Subject: Re: trying to learn plpqsql... so please forgive.. Date: Wed, 20 Nov 2002 14:27:41 -0800 X-Mailer: KMail [version 1.4] Cc: Michiel Lange , pgsql-sql@postgresql.org References: <5.1.0.14.0.20021120010436.00b4c920@192.168.1.3> <5.1.0.14.0.20021120225235.00b71db8@192.168.1.3> In-Reply-To: <5.1.0.14.0.20021120225235.00b71db8@192.168.1.3> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211201427.41550.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/320 X-Sequence-Number: 10462 Michiel, > And this function: > CREATE FUNCTION add_cust() RETURNS INT4 AS ' -- SERIAL data type is reall= y=20 > an INT4 (and some more). > BEGIN > RETURN NEW.my_key; > END; > ' LANGUAGE 'plpgsql'; >=20 > CREATE TRIGGER add_cust BEFORE INSERT ON mytable > FOR EACH ROW EXECUTE PROCEDURE add_cust(); >=20 > Ok, now I know it won't work... the idea was to use this with PHP in a=20 > webclient interface where the customer could give some information about= =20 > him/herself and then would be registered with the customer number generat= ed=20 > by the SERIAL type. > Would it work if I did a CREATE TRIGGER add_cust AFTER INSERT... ? (menti= on=20 > the AFTER instead of BEFORE) No, you can't return a value to the client from a Trigger. Not ever.=20= =20=20 Triggers modify data, and they can log stuff, but they can't return values = to=20 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= =20 solution I frequently use in my web apps. -Josh Berkus