Skip site navigation (1) Skip section navigation (2)

Re: Transaction-based insert w/PHP?

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: David Fetter <david(at)fetter(dot)org>,SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: Transaction-based insert w/PHP?
Date: 2003-02-13 00:52:45
Message-ID: 200302121652.45639.josh@agliodbs.com (view raw or flat)
Thread:
Lists: sfpug
David,

> Does fetching that OID inside a transaction automatically guarantee
> that the right thing happens?

Maybe, maybe not.  Regardless, you're making an easy task hard.  You'd be 
better off staying away from OIDs entirely:

> INSERT INTO foo (foo_desc)
> VALUES ('too much unix!')

> -- Fetch the $foo_id, or roll back if unable.

$new_foo = currval('foo_foo_id_seq')

> INSERT INTO bar (bar_desc, foo_id)
> VALUES ('never too much unix!', $new_foo)

I'd suggest reading the docs on sequences.  There is no reason for you ever to 
use OIDs at all.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

sfpug by date

Next:From: Dror MatalonDate: 2003-02-13 00:59:41
Subject: Re: Transaction-based insert w/PHP?
Previous:From: David FetterDate: 2003-02-12 20:35:07
Subject: Transaction-based insert w/PHP?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group