Re: ALTER SEQUENCE enchancement - Mailing list pgsql-hackers

From greg@turnstep.com
Subject Re: ALTER SEQUENCE enchancement
Date
Msg-id 854a891d0a7e5aec2972a0cd899e0d52@biglumber.com
Whole thread Raw
In response to Re: ALTER SEQUENCE enchancement  (Dennis Bjorklund <db@zigo.dhs.org>)
List 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@turnstep.com
PGP Key: 0x14964AC8 200312022159
-----BEGIN PGP SIGNATURE-----
iD8DBQE/zVV/vJuQZxSWSsgRArvaAKCM91V5su/AoOKXWVf+JhdrklRfQQCfXXfp
R7Pqjd/U0p+xSrS+sMxEoRE=
=FA6a
-----END PGP SIGNATURE-----





pgsql-hackers by date:

Previous
From: david@fetter.org (David Fetter)
Date:
Subject: Inside the Regex Engine
Next
From: Alvaro Herrera
Date:
Subject: Re: Inside the Regex Engine