pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
plpgsql select into question 2+ messages / 2 participants [nested] [flat]
* plpgsql select into question @ 2002-12-31 15:49 J D <jd88@hotmail.com> 0 siblings, 0 replies; 2+ messages in thread From: J D @ 2002-12-31 15:49 UTC (permalink / raw) To: pgsql-sql sorry if I've sent this to the wrong list... what is the proper way to do the following from within a plpgsql proc: (where table2 is a variable...) select into user_id max(id) from table2 This is part of a procedure that inserts a new record into table1 (table1 has an auto-incrementing id field). Then a trigger inserts a new record into table2 using max() to get the new id from table1 (the trigger fires after insert on table1), then the procedure updates table2. In order to update table2, I need to get the max(id) so I can do: update table2 set .... where id = user_id Thanks very much. And I'm grateful for ideas about a better strategy. cheers, jd _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 3 months FREE*. http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474&SU= http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_virusprotection_3mf ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: plpgsql select into question @ 2002-12-31 19:09 Jie Liang <jie@stbernard.com> 0 siblings, 0 replies; 2+ messages in thread From: Jie Liang @ 2002-12-31 19:09 UTC (permalink / raw) To: J D <jd88@hotmail.com>; pgsql-sql use 'INSERT INTO table1 ... SELECT ... ' stmt in your pgplsql. EXECUTE command is the way to execute a dynamic query in your function, read developer guide PL section of docs. Jie Liang -----Original Message----- From: J D [mailto:jd88@hotmail.com] Sent: Tuesday, December 31, 2002 7:50 AM To: pgsql-sql@postgresql.org Subject: [SQL] plpgsql select into question sorry if I've sent this to the wrong list... what is the proper way to do the following from within a plpgsql proc: (where table2 is a variable...) select into user_id max(id) from table2 This is part of a procedure that inserts a new record into table1 (table1 has an auto-incrementing id field). Then a trigger inserts a new record into table2 using max() to get the new id from table1 (the trigger fires after insert on table1), then the procedure updates table2. In order to update table2, I need to get the max(id) so I can do: update table2 set .... where id = user_id Thanks very much. And I'm grateful for ideas about a better strategy. cheers, jd _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 3 months FREE*. http://join.msn.com/?page=features/virus&xAPID=42&PS=47575&PI=7324&DI=7474&S U= http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_virusprotec tion_3mf ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-12-31 19:09 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2002-12-31 15:49 plpgsql select into question J D <jd88@hotmail.com> 2002-12-31 19:09 Re: plpgsql select into question Jie Liang <jie@stbernard.com>
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