Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Josh Berkus
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 ad

Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Michiel Lange
To those who pointed at the SELECT currval , thanks!, I think this is what I need instead of a trigger. So the real problem is solved I think. However I am quite curious about the plpgsql thing, I think I may need to use it, or may WANT to use it (performance wise... better to be as close as po

Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Josh Berkus
Michiel, > Maybe this should be sent to novice... I was not certain, but if it > should, please tell me so. No need to apologise. Novice would have been appropriate, but SQL is OK too. > When I do an 'INSERT INTO VALUES ' > and on the table is a serial primary key named p_key. > As I want thi

Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Johannes Lochmann
On Wednesday 20 November 2002 10:48, Henshall, Stuart - Design & Print wrote: > Michiel Lange wrote: > Trigger functions can only return type OPAQUE which isn't seen by the > client program. I just saw that in 7.3 the return type for triggers has changed to TRIGGER. HTH Johannes Lochmann --

Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Henshall, Stuart - Design & Print
Title: RE: [SQL] trying to learn plpqsql... so please forgive.. Michiel Lange wrote: > 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 ' &g

Re: [SQL] trying to learn plpqsql... so please forgive..

2002-11-20 Thread Luis Sousa
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. Try this: SELECT currval(); Luis Sousa smime.p7s De