pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adam Haberlach <adam@newsnipple.com>
To: Johnny Jørgensen <johnny@halfahead.dk>
Cc: pgsql-php@postgresql.org
Subject: Re: last OID and connections?
Date: Wed, 17 Oct 2001 12:18:23 -0700
Message-ID: <20011017121823.A8332@newsnipple.com> (raw)
In-Reply-To: <200110171527170784.01357C60@mail.halfahead.dk>
References: <200110171527170784.01357C60@mail.halfahead.dk>

On Wed, Oct 17, 2001 at 03:27:17PM +0200, "Johnny Jørgensen" wrote:
> Once I get a current project to production state, I'm going to get a heap of users performing updates simultaneously through the same update.php, and that raises a few questions:
> 
> 1. will pg_getlastoid() return the last oid inserted *by this user*, *on this page*, *on this connection*, or is there a possibility for them to get mixed up, because the database gets a connection from the same user (php), and reuses connections or something?

If you pass it the result object from your last insert, it should give
an oid unique to that insert.

I usually do the insert, the immediately read the row back with a select
for the pg_lastoid() in order to get the pkey.  A little wanky, but it
seems to be the way to do it.

> e.g. If a user changes his profile, and an administrator changes some other row at the same time?

If they are through seperate connections, they should be completely
different.

> 2. I find oid's pretty clever, but are they good for unique keys? It seems, foreign key constraints won't use oid's in the current release, should i use serials instead?

Don't use them for anything persistent except for large objects.  Use
serials as primary keys.


-- 
Adam Haberlach     | Computer science has the unfortunate characteristic
adam@newsnipple.com| that many of the pioneers of the field are still
                   | alive and doing research.
                   |        -- Adam Rifkin



view thread (3+ messages)

Message-ID: <20011017121823.A8332@newsnipple.com>
Permalink:  ../20011017121823.A8332@newsnipple.com/
Also on:    postgresql.org/message-id/20011017121823.A8332@newsnipple.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: adam@newsnipple.com, johnny@halfahead.dk
  Subject: Re: last OID and connections?
  In-Reply-To: <20011017121823.A8332@newsnipple.com>
  References: <200110171527170784.01357C60@mail.halfahead.dk> <20011017121823.A8332@newsnipple.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox