| From: | Dmitry Tkach <dmitry(at)openratings(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: A problem with sequences... |
| Date: | 2003-02-21 20:03:50 |
| Message-ID: | b35qve$vh5$1@news.hub.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
I got it!
For those, who are still wonderring, the actual problem had nothing to do with that rule.
I was loading some stuff into the database through a sql script (copy from etc...), and in the end of it I did:
select setval('answer_id_seq', id) from answer order by id desc limit 1;
Now, for some reason this reports a correct value, but what actually gets set is wrong!
Here is an example:
rapidb=# select max(id) from answer;
max
-------
25000
(1 row)
rapidb=# select last_value from answer_id_seq;
last_value
------------
22124
(1 row)
rapidb=# select setval ('answer_id_seq', id) from answer order by id desc limit 1;
setval
--------
25000
(1 row)
rapidb=# select currval('answer_id_seq');
currval
---------
21452
(1 row)
So, the question I have now is - what's going on?
How come setval() reports 25000, but the currval changes to 21452
If my query is wrong (and I can't really see what's wrong with it), then why does it report the correct value?
I have rewritten that script to do
select setval ('answer_id_seq', max(id)) from answer
instead, and that works fine... But I'd still love to find out what is wrong with that original query's behaviour...
Thanks!
Dima
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Neil Conway | 2003-02-21 20:08:07 | Re: reindex vs. drop index , create index |
| Previous Message | Bruno Wolff III | 2003-02-21 19:57:36 | Re: Problem with functional indexes |