Re: OID Usage - Mailing list pgsql-general

From Christian Kratzer
Subject Re: OID Usage
Date
Msg-id 20050114102431.W6920@vesihiisi.cksoft.de
Whole thread Raw
In response to Re: OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
Responses Re: OID Usage  (Michael Fuhr <mike@fuhr.org>)
Re: OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
List pgsql-general
Hi,

On Fri, 14 Jan 2005, Bo Lorentsen wrote:

> Michael Glaesemann wrote:
>
>> You can use currval() to get the sequence value that was pulled from your
>> insert. You can check the documentation for usage, as well as searching
>> the archives for discussions of using OIDs as part of your database logic.
>
> I know this, but i like not to know anything about the metadata of the table
> i use. Basicly using the same functionality, as given in mysql in the
> mysql_insert_id, as I use the same low level code for both DB's (until my
> boss give in totally to PG :-)).

why should your application not want to know about the metadata of it's
own tables ? That sounds quite strange when you think about it.

If you name your sequences in a generic way you can alway construct the
name of the sequence from the name of the table and the id column.

We use this in our php framework

         function insert_id()
         {
                 global $pg_conn;
                 if(isset($pg_conn)) {
                         $query = sprintf("SELECT currval('%s_%s_seq') AS id",$this->table,$this->id_column);
                         $result = @pg_query($pg_conn,$query);
                         $row = pg_fetch_assoc($result);
                         return strval($row["id"]);
                 } else {
                         return 0;
                 }
         }

Greetings
Christian

--
Christian Kratzer                       ck@cksoft.de
CK Software GmbH                        http://www.cksoft.de/
Phone: +49 7452 889 135                 Fax: +49 7452 889 136

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Functions that return RECORD type
Next
From: Michael Fuhr
Date:
Subject: Re: OID Usage