Search Postgresql Archives

Defining and Using variables in a postgres function

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

 



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


[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