Re: ALTER SEQUENCE enchancement

From: greg(at)turnstep(dot)com
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER SEQUENCE enchancement
Date: 2003-12-03 03:17:09
Message-ID: 854a891d0a7e5aec2972a0cd899e0d52@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> The above is an operation that would not help me a lot, but a way of
> performing currval() without knowing the sequence name would be good.

You could do this with a function. Here is a quick one in SQL:

CREATE OR REPLACE FUNCTION seqname(NAME,NAME) RETURNS TEXT AS '
SELECT TRIM(BOTH \'\'\'\' FROM SUBSTRING(d.adsrc, \'\'\'.*\'\'\'))
FROM pg_catalog.pg_attrdef d, pg_catalog.pg_attribute a, pg_class c
WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef
AND c.relname = $1
AND c.oid = a.attrelid
AND a.attname = $2;
' LANGUAGE SQL;

Usage: SELECT nextval(seqname('tablename','colname'));

You might also want to simply keep a table of the sequence names
if you plan on doing this a lot, or make sure you name them in
a consistent and unsurprising manner.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200312022159

-----BEGIN PGP SIGNATURE-----

iD8DBQE/zVV/vJuQZxSWSsgRArvaAKCM91V5su/AoOKXWVf+JhdrklRfQQCfXXfp
R7Pqjd/U0p+xSrS+sMxEoRE=
=FA6a
-----END PGP SIGNATURE-----

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2003-12-03 03:38:42 Re: Inside the Regex Engine
Previous Message David Fetter 2003-12-03 01:52:57 Inside the Regex Engine