Re: determine sequence name for a serial

From: Robby Russell <robby(at)planetargon(dot)com>
To: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: determine sequence name for a serial
Date: 2004-10-28 23:07:36
Message-ID: 1099004856.11172.18.camel@vacant
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2004-10-28 at 16:51 -0600, Ed L. wrote:
> On Thursday October 28 2004 11:42, Robby Russell wrote:
> >
> > Thanks, this seems to work well. My goal is to actually create a php
> > function that takes a result and returns the insert_id like
> > mysql_insert_id() does, but without needing to know the sequence names
> > and such. I would make a psql function, but I don't always have that
> > option with some clients existing systems.
>
> An alternative is to simply select nextval() from a separately-created
> sequence object to get the serial value, then insert with that value. No
> need to have a serial column then, but you do need to explicitly create the
> sequence object, as opposed to SERIAL.
>

nextval, currval, either way, I would need to know the specific sequence
name. Was looking for a good way to pass a function a schema and table
and return a sequence. I got exactly what I was looking for and have
been able to build a function that will handle this for me. It's part of
a db layer class that I use with mysql and pgsql, and was using
mysql_insert_id and wanted to model a function that would return an id
like the mysql_insert_id function does. (one of the few pgsql/php
functions that doesn't exist in php natively..but does with mysql)

-Robby

--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robby(at)planetargon(dot)com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now supporting PHP5 ---
****************************************/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2004-10-28 23:21:52 Re: Turning a subselect into an array
Previous Message Ed L. 2004-10-28 22:51:05 Re: determine sequence name for a serial