Re: OID Usage

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Bo Lorentsen <bl(at)netgroup(dot)dk>
Cc: Christian Kratzer <ck(at)cksoft(dot)de>, 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 14:31:08
Message-ID: 20050114143108.GD21340@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 14, 2005 at 11:39:54AM +0100, Bo Lorentsen wrote:

> Thanks, but this demands you to have the table and id_column name in
> your hand, and I don't right now.

You can create a function to get the sequence name attached to a table.
Of course, you should take into account the fact that there could be
more than one (two serial fields in a table are rare but not
impossible), but if your tables have only one sequence you should be OK.
Something with

select relname, relkind
from pg_depend join pg_class on (oid = objid)
where pg_depend.refobjid = 'foo'::regclass
and relkind = 'S';

(only lightly tested). Then you can use that to construct your argument
to the nextval() function.

> Also ... the "currval" function are specifik to postgresql, and there
> are nothing like it in mysql that can make any garanti for getting row
> for newly inserted data. You can access autoincrement values in mysql,
> but no garanties are given about its value (someone else have inserted a
> new in the same table).

This doesn't happen with sequences on Postgres. The value you get is
guaranteed to be the one the sequence generated for you.

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"Those who use electric razors are infidels destined to burn in hell while
we drink from rivers of beer, download free vids and mingle with naked
well shaved babes." (http://slashdot.org/comments.pl?sid=44793&cid=4647152)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tony Caduto 2005-01-14 14:40:53 Re: Version Control Software for Database Objects
Previous Message TOUBLANC Christophe 2005-01-14 14:05:07 Open Source Database Opportunity