Re: ALTER SEQUENCE enchancement
От | greg@turnstep.com |
---|---|
Тема | Re: ALTER SEQUENCE enchancement |
Дата | |
Msg-id | 854a891d0a7e5aec2972a0cd899e0d52@biglumber.com обсуждение исходный текст |
Ответ на | Re: ALTER SEQUENCE enchancement (Dennis Bjorklund <db@zigo.dhs.org>) |
Список | 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 по дате отправления: