From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Christian Kratzer <ck(at)cksoft(dot)de> |
Cc: | Bo Lorentsen <bl(at)netgroup(dot)dk>, Michael Glaesemann <grzm(at)myrealbox(dot)com>, "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: OID Usage |
Date: | 2005-01-14 10:15:08 |
Message-ID: | 20050114101508.GA98256@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Jan 14, 2005 at 10:32:18AM +0100, Christian Kratzer wrote:
> $query = sprintf("SELECT currval('%s_%s_seq') AS
> id",$this->table,$this->id_column);
PostgreSQL 8.0 will have a pg_get_serial_sequence() function that
returns the sequence name for a particular column so you don't have
to construct it. This is useful when a table or column has been
renamed, in which case the above will probably break.
CREATE TABLE foo (fooid serial);
ALTER TABLE foo RENAME TO bar;
ALTER TABLE bar RENAME fooid TO barid;
\d bar
Table "public.bar"
Column | Type | Modifiers
--------+---------+--------------------------------------------------------
barid | integer | not null default nextval('public.foo_fooid_seq'::text)
SELECT pg_get_serial_sequence('bar', 'barid');
pg_get_serial_sequence
------------------------
public.foo_fooid_seq
(1 row)
INSERT INTO bar VALUES (DEFAULT);
SELECT currval(pg_get_serial_sequence('bar', 'barid'));
currval
---------
1
(1 row)
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
From | Date | Subject | |
---|---|---|---|
Next Message | Bo Lorentsen | 2005-01-14 10:39:54 | Re: OID Usage |
Previous Message | Christian Kratzer | 2005-01-14 09:32:18 | Re: OID Usage |