pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
return value of the trigger function 2+ messages / 2 participants [nested] [flat]
* return value of the trigger function @ 2005-01-10 14:15 Jarek Pudełko <jarek.pudelko@tech.ceti.pl> 2005-01-15 09:00 ` Re: return value of the trigger function Bruno Wolff III <bruno@wolff.to> 0 siblings, 1 reply; 2+ messages in thread From: Jarek Pudełko @ 2005-01-10 14:15 UTC (permalink / raw) To: pgsql-sql Hi I have big problem with a trigger function. Defs: CREATE TABLE foo (id int2, name varchar(20)); foo.id cannot be serial or autoint because it will not be unique. Now I need a trigger that return foo.id of the inserted record. INSERT INTO foo VALUES (max(foo.id)+1,'junk'); IMHO the trigger should be: CREATE TRIGGER tr_get_new_id AFTER INSERT on foo ON EACH ROW EXECUTE PROCEDURE get_new_id(); But I cannot create the function :( I don't know what type should be input and how about output? trigger or int2? TIA, -- Jarek Pudelko JP272-RIPE ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: return value of the trigger function 2005-01-10 14:15 return value of the trigger function Jarek Pudełko <jarek.pudelko@tech.ceti.pl> @ 2005-01-15 09:00 ` Bruno Wolff III <bruno@wolff.to> 0 siblings, 0 replies; 2+ messages in thread From: Bruno Wolff III @ 2005-01-15 09:00 UTC (permalink / raw) To: Jarek Pude?ko <jarek.pudelko@tech.ceti.pl>; +Cc: pgsql-sql On Mon, Jan 10, 2005 at 15:15:33 +0100, Jarek Pude?ko <jarek.pudelko@tech.ceti.pl> wrote: > Hi > > I have big problem with a trigger function. > Defs: > > CREATE TABLE foo (id int2, name varchar(20)); > > foo.id cannot be serial or autoint because it will not be unique. > > Now I need a trigger that return foo.id of the inserted record. > > INSERT INTO foo VALUES (max(foo.id)+1,'junk'); If you are really doing the above, you probably do want to use serial. If you insist on not doing this your app should do something like lock table, select max(foo.id)+1 from id, and then nsert using the value returned bye the select and then whatever else you want to do. > > > IMHO the trigger should be: > > CREATE TRIGGER tr_get_new_id > AFTER INSERT on foo > ON EACH ROW > EXECUTE PROCEDURE get_new_id(); > > But I cannot create the function :( > I don't know what type should be input and how about output? trigger or > int2? > > TIA, > > > -- > Jarek Pudelko > JP272-RIPE > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-01-15 09:00 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2005-01-10 14:15 return value of the trigger function Jarek Pudełko <jarek.pudelko@tech.ceti.pl> 2005-01-15 09:00 ` Bruno Wolff III <bruno@wolff.to>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox