Referencing serial col's sequence for insert

Поиск
Список
Период
Сортировка
От Anil Menon
Тема Referencing serial col's sequence for insert
Дата
Msg-id CAHzbRKeftnspi8dPJPP9A0ktPMuKHkb3GPA=3hHbtJ8n45WPqw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Referencing serial col's sequence for insert
Список pgsql-general
Hi,

I have a question on the right/correct practice on using the serial col's sequence for insert.

Best way of explanation is by an example:

create table id01 (col1 serial, col2 varchar(10));

insert into id01(col2) values ( 'data'||currval('id01_col1_seq')::varchar);

while I do get what I want:

select  * from id01;
 col1 | col2
------+-------
    1 |
data1

Is this guaranteed to work : I am assuming that an insert triggers the id01_col1_seq's nextval first hence using
id01_col1_seq's currval subsequently will have the "correct" / expected value (and not the previous value before the insert).

Is my assumption correct?

Thanks in advance,
AK


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

Предыдущее
От: Jakub Jindra
Дата:
Сообщение: Re: giving a user permission to kill their processes only
Следующее
От: Sergiy Zuban
Дата:
Сообщение: postgres_fdw - IS TRUE/FALSE conditions are not pushed down