pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedwrong value returned?
2+ messages / 2 participants
[nested] [flat]
* wrong value returned?
@ 2008-06-11 14:04 mike.gagnon@bellnet.ca
0 siblings, 1 reply; 2+ messages in thread
From: mike.gagnon@bellnet.ca @ 2008-06-11 14:04 UTC (permalink / raw)
To: pgsql-odbc
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: wrong value returned?
@ 2008-06-11 16:28 Fred Parkinson <FredP@abag.ca.gov>
parent: mike.gagnon@bellnet.ca
0 siblings, 0 replies; 2+ messages in thread
From: Fred Parkinson @ 2008-06-11 16:28 UTC (permalink / raw)
To: mike.gagnon@bellnet.ca; 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.gagnon@bellnet.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
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2008-06-11 16:28 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 14:04 wrong value returned? mike.gagnon@bellnet.ca
2008-06-11 16:28 ` Fred Parkinson <FredP@abag.ca.gov>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox