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