Re: lastval()

From: Alvaro Herrera <alvherre(at)surnet(dot)cl>
To: John Hansen <john(at)geeknet(dot)com(dot)au>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Neil Conway <neilc(at)samurai(dot)com>, Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>, pgsql-patches(at)postgresql(dot)org
Subject: Re: lastval()
Date: 2005-05-11 12:45:35
Message-ID: 20050511124535.GB7133@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

On Wed, May 11, 2005 at 02:08:16PM +1000, John Hansen wrote:

> Take for instance this (overly simplified) function used in a program
> that builds the query strings dynamically:
>
> int64 runquery(char *query) {
> PQexec(query);
> result = Pqexec("SELECT lastval()");
> return result;
> }
>
> The program expects this function to return the 'id' that was inserted,
> or 0 if the table didn't contain a sequence or it wasn't an insert.
>
> Rewriting that would take a considerable effort.

Actually, having it throw an error would be helpful, because then you
can find in the application which calls should be replaced by the
generic runquery() that has to return nothing versus the one that has to
return a sequence value. So porting is a little more involved but
more useful in the end.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-05-11 13:19:57 Re: [PATCHES] Cleaning up unreferenced table files
Previous Message Mahmoud Taghizadeh 2005-05-11 08:07:07 Where is Translation of "FARSI" FAQ?