Re: [COMMITTERS] pgsql-server: Clean up generation of default

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [COMMITTERS] pgsql-server: Clean up generation of default
Date: 2004-06-11 06:16:04
Message-ID: D1A9144A-BB6E-11D8-B1AB-000A95C88220@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers


On Jun 11, 2004, at 1:02 PM, Christopher Kings-Lynne wrote:

>> 3. Or even create a pg_get_sequence() function:
>> SELECT SETVAL(pg_get_sequence(schema.table, col), 17);
>
> Actually, this is the best solution :)

John Hansen and I worked this up. It works, though it's not
schema-aware, afaict.

create or replace function last_val(
text -- tablename
, text -- colname
) returns bigint
language 'sql' as '
select currval(
(select
split_part(adsrc,\'\'\'\',2) as seq
from pg_class
join pg_attribute on (pg_class.oid = pg_attribute.attrelid)
join pg_attrdef
on (pg_attrdef.adnum = pg_attribute.attnum
and pg_attrdef.adrelid = pg_attribute.attrelid)
where pg_class.relname = $1
and pg_attribute.attname = $2)
);
';

Might be a starting point.

Michael Glaesemann
grzm myrealbox com

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Christopher Kings-Lynne 2004-06-11 12:51:39 Re: [COMMITTERS] pgsql-server: Clean up generation of default
Previous Message Bruce Momjian 2004-06-11 04:17:25 pgsql-server: Another fix for Win32 START.

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2004-06-11 07:07:58 Re: Nested transactions and tuple header info
Previous Message Tom Lane 2004-06-11 05:28:35 Re: More vacuum.c refactoring