Re: creating a table with a serial column sets currval

Поиск
Список
Период
Сортировка
От Kris Jurka
Тема Re: creating a table with a serial column sets currval
Дата
Msg-id Pine.BSO.4.64.0710181919160.5403@leary.csoft.net
обсуждение исходный текст
Ответ на Re: creating a table with a serial column sets currval  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: creating a table with a serial column sets currval
Список pgsql-bugs
On Thu, 18 Oct 2007, Tom Lane wrote:

>> Looks like any alter sequence command will do this.  The serial case uses
>> alter sequence owned by under the hood which exposes this.  The problem is
>> that altering the sequence puts it into the SeqTable cache list when it
>> really shouldn't be.
>
> It's not that it gets put in the cache, it's that read_info gets called
> (setting elm->increment).  I think we probably should clean this up by
> creating a separate flag in that struct that explicitly says "currval is
> valid", which would be set by nextval(), setval() (because historically
> it's acted that way), and I guess ALTER SEQUENCE RESTART WITH (for
> consistency with setval()).

Personally I think setval should only set validCurrval and the last_value
if iscalled = true.  If is_called = false I think it should retain the
previous last_value if any until the next nextval call.

jurka=# create sequence s;
CREATE SEQUENCE
jurka=# select nextval('s');
  nextval
---------
        1
(1 row)

jurka=# select setval('s',5, false);
  setval
--------
       5
(1 row)

jurka=# select currval('s');
  currval
---------
        5
(1 row)

Should return 1 instead of 5.

Kris Jurka

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Oliver Jowett
Дата:
Сообщение: Re: [JDBC] Re: 'on insert do instead' rule with a where clause responds 'INSERT 0 0'
Следующее
От: "Ciprian Dorin Craciun"
Дата:
Сообщение: Fwd: Stalled post to pgsql-bugs