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

Re: wrong value returned?

From: "Fred Parkinson" <FredP(at)abag(dot)ca(dot)gov>
To: <mike(dot)gagnon(at)bellnet(dot)ca>, <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: wrong value returned?
Date: 2008-06-11 16:28:55
Message-ID: 484F9AD7020000A700007E91@groupwise.abag.ca.gov (view raw or flat)
Thread:
Lists: pgsql-odbc
This doesn't explain the error, but solves the problem for me: use a query like
SELECT Max(registration_id) AS MaxID FROM registrations;

Another solution, if you are using a sequenced serial value, is to use the 'last_value' function on the sequencing table:
select registration_registration__seq.last_value  from registration_registration__seq;


>>> <mike(dot)gagnon(at)bellnet(dot)ca> 06/11/2008 7:04 AM >>>
Hi,

I've setup a query in my program to get the biggest value used in my "customers" table.  There is a serial column called customer_id.  I use the following query within my program and it returns, lets say, 3.  If I run the same query from the psql console window (over and over and at the same point where I've stepped to in my program), it will consistently return 2 whereas the program will consistently return 3 (always one more).

Here is the query to get the last ID used:
SELECT customer_id from customers order by customer_id DESC limit 1;

I do one fetch and have my result programmatically which is always 1 more than the value returned by the psql console window method.  What gives?

Many thanks,
Mike

In response to

pgsql-odbc by date

Next:From: Richard BroersmaDate: 2008-06-11 17:48:23
Subject: ODBC escape convert error
Previous:From: mike.gagnonDate: 2008-06-11 14:04:22
Subject: wrong value returned?

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