Skip site navigation (1) Skip section navigation (2)

Re: calling currval() before nextval() patch adding

From: Rod Taylor <pg(at)rbt(dot)ca>
To: John Hansen <john(at)geeknet(dot)com(dot)au>
Cc: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: calling currval() before nextval() patch adding
Date: 2004-11-07 23:39:31
Message-ID: 1099870771.74062.19.camel@home (view raw or flat)
Thread:
Lists: pgsql-patches
On Sun, 2004-11-07 at 17:21, John Hansen wrote:
> Hi list,
> 
> attached, cvs context diff that adds currval_isset('sequence_name');


> With this patch, I can now call currval_isset to determine if I need to
> call currval. Previously, I just called currval, but with the result of
> filling up the server log with warnings.

This might do what you're looking for on 8.0.

CREATE OR REPLACE FUNCTION currval_isset(text) RETURNS bigint AS '
DECLARE
  var integer;
BEGIN
  SELECT currval($1) INTO var;

  RETURN var;

EXCEPTION
  WHEN 	OBJECT_NOT_IN_PREREQUISITE_STATE THEN
    RETURN 0;
END;
' LANGUAGE plpgsql;

SELECT isset('tst_seq');



In response to

Responses

pgsql-patches by date

Next:From: Tom LaneDate: 2004-11-07 23:48:08
Subject: Re: calling currval() before nextval() patch adding currval_isset()
Previous:From: Peter EisentrautDate: 2004-11-07 23:38:14
Subject: Re: Romanian translation for 8.0: new file (psql)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group