Search Postgresql Archives

Re: OID Usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux