Re: sequence

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: sequence
Дата
Msg-id dcc563d10712090804r78543a9ci74b6da563d07d2e7@mail.gmail.com
обсуждение исходный текст
Ответ на Re: sequence  ("Alain Roger" <raf.news@gmail.com>)
Ответы Re: sequence  (Michael Schmidt <MichaelMSchmidt@msn.com>)
Список pgsql-general
On Dec 9, 2007 9:56 AM, Alain Roger <raf.news@gmail.com> wrote:
> Hi Tom,
>
> but when i let pgsql setup everything (i mean when i create table -> pgsql
> creates sequence)
> ), i have called = no, before using any select nextval()...
> and in this case, it works great.
>
> but once called = yes, select nextval(sequence_name); always gives me
> current value +1 :-(

The whole point of the serial type is that you don't have to call
nextval yourself.

smarlowe=# create table test (i serial primary key, info text);
NOTICE:  CREATE TABLE will create implicit sequence "test_i_seq" for
serial column "test.i"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"test_pkey" for table "test"
CREATE TABLE
smarlowe=# insert into test (info) values ('this is a row');
INSERT 0 1
smarlowe=# select * from test;
 i |     info
---+---------------
 1 | this is a row

If you need the current value to insert into another table, you use currval:

smarlowe=# select currval('test_i_seq');
 currval
---------
       1

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

Предыдущее
От: "Alain Roger"
Дата:
Сообщение: Re: sequence
Следующее
От: "Alain Roger"
Дата:
Сообщение: insert into...