Thread: Function For Newly INSERTED VALUE

Function For Newly INSERTED VALUE

From
"shreedhar"
Date:
Hi All,

The following function is possible where input is 'Sequence Name' and output
is 'Inserted value' language 'plpgsql'

DECLARE
 sequence ALIAS FOR $1;
 inserted_rec integer;
 sql text;
BEGIN
 sql := 'SELECT INTO inserted_rec *  from ' || sequence;
 EXECUTE sql;
 IF inserted_rec.last_value IS NULL THEN
   RETURN 0;
 ELSE
   RETURN inserted_rec.last_value;
 END IF;
END;

The same is working for the following

DECLARE
 sequence ALIAS FOR $1;
 inserted_rec integer;
 sql text;
BEGIN
SELECT INTO inserted_rec *  from  sequencename;
 IF inserted_rec.last_value IS NULL THEN
   RETURN 0;
 ELSE
   RETURN inserted_rec.last_value;
 END IF;
END;

How can I make use the top one.

With Best Regards,
Sreedhar Bhaskararaju 1,2nd Main Road, KottuGardens, Chennai - 600 085 Ph :
4475111 Email : shreedhar@lucidindia.net