Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Retrieving the new nextval...: msg#00390

db.postgresql.sql

Subject: Re: Retrieving the new nextval...

Hi all,
I'm in trouble with the same problem, but in PHP..
With your solution, I cannot be totally sure that last
inserted raw was mine...
Because I'm on a web page, it could be that, as soon
as I've inserted my record, another one do an
insertion, so I would get the wrong ID...
does transactions resolve this, in Psql???
I thought to solve it with a similiar solution,
working in transactions inserting a raw and
immedialtly after read from DB last raw, but who
assure me that all will go right??
If I was on a server app., I (and you, if it is your
case) would insert a timestamp, and then I'd select
from table where timestamp = mysavedtime;
But in my case there could be two or more equals
timestamp, cause there's not only one application
working with DB...
I'm still reading, searching, trying...
ciao
danilo



--- Kevin Brannen <kevinb@xxxxxxxxxxxxxxxx> ha
scritto: > Greg Patnude wrote:
> > I am using postgreSQL with Perl::CGI and
> Perl::DBI::Pg... I would like to be
> > able to insert a row from my Perl script
> [$SQL->exec();] and have postgreSQL
> > return the id of the newly inserted record
> (new.id) directly to the Perl
> > script for further processing... Anyone with a
> solution / idea ???
> >
> > Nearly EVERY table I create in postgreSQL (7.2)
> has the following minimum
> > structure:
> >
> > create table "tblName" (
> >
> > id int4 primary key nextval
> ("tblName_id_seq"),
> >
> > ..field...
> > )
>
> You can either do it in 2 statements, something
> like:
>
> $dbh->do("insert into tblName ...");
> my ($id) = $dbh->selectrow_array("select
> currval('tblName_id_seq')");
>
> Or you could create a function which takes the
> insert statement, and
> ends with doing a select on the currval (as above)
> and returning that.
> As I do the 2 statement approach above, I haven't
> done a function, but
> it doesn't look like it would be that hard to do.
>
> HTH,
> Kevin
R

______________________________________________________________________
Yahoo! Musica: notizie, recensioni, classifiche, speciali multimediali
http://it.yahoo.com/mail_it/foot/?http://it.music.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@xxxxxxxxxxxxxx



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
user-groups.jax...    php.zend.framew...    os.solaris.open...    web.quixote.use...    java.openjdk.ho...    ietf.secmech/20...    gnu.glpk/2004-0...    recreation.cars...    network.smokepi...    linux.drivers.i...    cms.opencms.dev...    fonts.gfontview...    text.xml.soap.u...    voip.nist-sip/2...    debian.ports.hp...    xfree86.interna...    science.biology...    qnx.openqnx.dev...    mail.sylpheed.c...    busybox/bios/20...    emulators.kvm.s...    hardware.openco...    apple.fink.begi...    kde.german/2006...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation