Search Postgresql Archives

Re: Defining and Using variables in a postgres function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 1, 2007, at 12:09 PM, Harpreet Dhaliwal wrote:
For inserting the id, i need to query a table xyz, fetch the maximum id in it, increment it by 1 and store it in tbl_email. Right after BEGIN in my function I have a commnet where in I need to query the xyz table, fetch the max id and store it in a variable and then I can increment this variable and store it in tbl_email.

That's not safe unless you get an exclusive lock on the table before the select.

Why don't you just use a sequence/serial?

How should i define this variable first and how to push the result of the query fired on table xyz.

SELECT INTO v_max_id
	max(id)
	FROM table
;
--
Jim Nasby                                            jim@xxxxxxxxx
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux