Function For Newly INSERTED VALUE - Mailing list pgsql-admin

From shreedhar
Subject Function For Newly INSERTED VALUE
Date
Msg-id 002601c25a2c$7372f610$1201a8c0@a4005
Whole thread Raw
List pgsql-admin
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


pgsql-admin by date:

Previous
From: "Marc Mitchell"
Date:
Subject: TPS benchmarks for an active system
Next
From: Krammer Clemens
Date:
Subject: disk spin down