Re: Using oid as pkey

From: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>, Postgres-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using oid as pkey
Date: 2007-08-20 22:51:09
Message-ID: 46CA1ADD.5030306@lorenso.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Glaesemann wrote:
>
> On Aug 20, 2007, at 16:58 , Ed L. wrote:
> You'd have to specify your table WITH OIDS anyway as they're no longer used by
> default for table rows, so there's really nothing to be gained by using
> oids.

How exactly can you get rid of OIDs when using a language like PHP? The
"magic" of SERIAL and BIGSERIAL is that they are supposed to be like
MySQL's AUTO INCREMENT feature and they create their own SEQUENCE for
you automatially to handle the serialization. Yet, I can't get the
value of the serial column without knowing the name of the serial sequence.

Using a brain-dead sample table that looks like this:

CREATE table some_table (
col0 SERIAL,
col1 VARCHAR,
col2 VARCHAR
);

I want to do something like this:

INSERT INTO some_table (col1, col2)
VALUES ('val1', 'val2');

I want the value of col0 returned to the application and I don't want to
know the name of the sequence involved in the SERIAL column. I just
want the value inserted into the column by using just it's column name.

In PHP with PDO, I've only been able to get this by first finding the
OID value from 'lastInsertId' and then using that OID to run this select:

SELECT $column AS last_inserted_id
FROM $table
WHERE oid = ?

How else could this be done without the round-trip back the db server or
knowing too much about the SERIAL internals that I shouldn't really need
to know?

-- Dante

>
> Michael Glaesemann
> grzm seespotcode net
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-08-20 22:56:14 Re: Using oid as pkey
Previous Message Scott Marlowe 2007-08-20 22:30:48 Re: Using oid as pkey