Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A5698475AD7 for ; Tue, 19 Nov 2002 19:16:11 -0500 (EST) Received: from minas.demon.nl (minas-2.demon.nl [212.238.194.105]) by postgresql.org (Postfix) with ESMTP id 0DD5547592C for ; Tue, 19 Nov 2002 19:16:10 -0500 (EST) Received: from depastor.minas.demon.nl (minas.pastoraat [192.168.1.1]) by minas.demon.nl (8.11.4/8.11.4) with ESMTP id gAK8bZQ02083 for ; Wed, 20 Nov 2002 09:37:35 +0100 Message-Id: <5.1.0.14.0.20021120010436.00b4c920@192.168.1.3> X-Sender: michiel@192.168.1.3 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 20 Nov 2002 01:16:12 +0100 To: pgsql-sql@postgresql.org From: Michiel Lange Subject: trying to learn plpqsql... so please forgive.. Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/290 X-Sequence-Number: 10432 Maybe this should be sent to novice... I was not certain, but if it should, please tell me so. The matter at hand is this: When I do an 'INSERT INTO VALUES ' and on the table is a serial primary key named p_key. As I want this number to be auto-generated, but use it as a 'customer number', I want to create this function to return the value of this insert. I thought/hoped that this would work, but as there are some people dependant on this database, I dare not try out too much ;-) This would be the first time I used plpgsql, so I am not so certain about what I do. CREATE FUNCTION add_cust() RETURNS INT4 AS ' -- SERIAL data type is really an INT4 (and some more). BEGIN RETURN NEW.p_key; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER add_cust BEFORE INSERT ON table FOR EACH ROW EXECUTE PROCEDURE add_cust(); Someone willing to evaluate this for me, and telling me if it is safe to use as it is? or things I may do wrong? TIA, Michiel