---------- Forwarded message ----------
From: Sean Thayne <[EMAIL PROTECTED]>
Date: Wed, Oct 22, 2008 at 5:29 PM
Subject: Re: [UPHPU] Postgres Insert ID
To: Grant Shipley <[EMAIL PROTECTED]>


I'm pretty sure that if this was the case before, it's definitely fixed now.
I'm actually a big fan of last_insert_id(), it saves me the time of having
to check the database for the sequence name and placing another call.

With mysql I can do this

mysqli_query(
"INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)"
);
$newId = mysqli_last_insert_id();


Where in Postgres I need extra info
pg_query(
"INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)"
);
$sequenceQuery = pg_query("SELECT curval(seq_city_id)");
$result = pg_fetch_assoc($sequenceQuery);
$newId = $result[0];

Seems like extra work for no extra benefit, I've used mysql on large
clusters, and the only thing your need to do is add a auto_increment offset
to avoid duplicate primary keys, but that's a one time deal. I know I'm
complaining over an extra two lines of code. But it just seems like a waste
of time.

It does sound like MySQL added this for their own database, and it's
probally not part of the sql standard, but I think it would be nice feature
to add to all databases... Unless theirs some reason I'm missing....


On Wed, Oct 22, 2008 at 5:12 PM, Grant Shipley <[EMAIL PROTECTED]> wrote:

> On Wed, Oct 22, 2008 at 5:20 PM, Sean Thayne <[EMAIL PROTECTED]> wrote:
> > ---------- Forwarded message ----------
> > From: Sean Thayne <[EMAIL PROTECTED]>
> > Date: Wed, Oct 22, 2008 at 3:20 PM
> > Subject: Re: [UPHPU] Postgres Insert ID
> > To: [EMAIL PROTECTED]
> >
> >
> > Thanks, that's a bummer, wonder by Postgres doesn't have a feature like
> > this. Don't most database servers have a equivalent function?
> >
>
> IMO, the auto increment in mysql is dreadful.  Sequences are much
> better.  Oracle use sequences in the same fashion that postgres does.
> Keep in mind that last_insert_id only returns the last insert id on
> that connection... so if you are connection pooled / clustered you
> will not get the result you are hoping for.  (I could be wrong on this
> but this is what I remember when I used mysql last with PHP)
>

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to