Re: [GENERAL] Defining and Using variables in a postgres function

2007-02-02 Thread Bruno Wolff III
On Fri, Feb 02, 2007 at 17:18:39 +0100, Alban Hertroys <[EMAIL PROTECTED]> wrote: > > You can do this: > INSERT INTO tbl_email (option_public, agency, id) > SELECT $1, $2, MAX(id) + 1 > FROM xyz; > > I just realize you don't so much need a lock, you need a serialized > transaction. I ca

Re: [GENERAL] Defining and Using variables in a postgres function

2007-02-02 Thread Jim Nasby
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

Re: [GENERAL] Defining and Using variables in a postgres function

2007-02-02 Thread Alban Hertroys
Harpreet Dhaliwal wrote: > About the concurrency control, if i have both Select Max(id) and insert > (id) You know, if you don't top-post you don't need to tell me what you're talking about ;) > in the same function, then would it be > a nice idea to put both these statements in the same function

Re: [GENERAL] Defining and Using variables in a postgres function

2007-02-02 Thread Harpreet Dhaliwal
About the concurrency control, if i have both Select Max(id) and insert (id) in the same function, then would it be a nice idea to put both these statements in the same function or differenct functions and then put the insert in a transaction and lock the table for any further query till insert co

Re: [GENERAL] Defining and Using variables in a postgres function

2007-02-02 Thread Alban Hertroys
Harpreet Dhaliwal wrote: > I have a function like the follwoing: > > CREATE OR REPLACE FUNCTION sp_insert_raw_email(bool, text, text, text, > int4,text,text,text,text,text,text,text,timestamp) > RETURNS void AS > $BODY$ > BEGIN > -- SELECT STATEMENT GOES HERE-- > INSERT INTO tbl_email(option_publ

[GENERAL] Defining and Using variables in a postgres function

2007-02-01 Thread Harpreet Dhaliwal
I have a function like the follwoing: CREATE OR REPLACE FUNCTION sp_insert_raw_email(bool, text, text, text, int4,text,text,text,text,text,text,text,timestamp) RETURNS void AS $BODY$ BEGIN -- SELECT STATEMENT GOES HERE-- INSERT INTO tbl_email(option_public, agency , id) VALUES ($1,$2) ; END; $B