Defining and Using variables in a postgres function - Mailing list pgsql-general

From Harpreet Dhaliwal
Subject Defining and Using variables in a postgres function
Date
Msg-id d86a77ef0702010909m59f6b656u141238224ba4d447@mail.gmail.com
Whole thread Raw
Responses Re: Defining and Using variables in a postgres function  (Alban Hertroys <alban@magproductions.nl>)
Re: Defining and Using variables in a postgres function  (Jim Nasby <decibel@decibel.org>)
List pgsql-general
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;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE;


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.

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

Thanks in advance,
~Harpreet

pgsql-general by date:

Previous
From: Bill Moran
Date:
Subject: Re: I "might" have found a bug on 8.2.1 win32
Next
From: Tony Caduto
Date:
Subject: Re: I "might" have found a bug on 8.2.1 win32