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

From Michael Glaesemann
Subject Re: [COMMITTERS] pgsql-server: Clean up generation of default
Date
Msg-id D1A9144A-BB6E-11D8-B1AB-000A95C88220@myrealbox.com
Whole thread Raw
In response to Re: [COMMITTERS] pgsql-server: Clean up generation of default  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Responses Re: [COMMITTERS] pgsql-server: Clean up generation of default
List 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
joinpg_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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: More vacuum.c refactoring
Next
From: Alvaro Herrera
Date:
Subject: Re: Nested transactions and tuple header info