Re: The best option to insert data with primary id

Поиск
Список
Период
Сортировка
От mike@if-then-else.pl
Тема Re: The best option to insert data with primary id
Дата
Msg-id 20101206162725.o3q9xfug2ioo08g8@horde.iq.pl
обсуждение исходный текст
Ответ на The best option to insert data with primary id  (- <grandebuzon@gmail.com>)
Список pgsql-sql
Quoting - <grandebuzon@gmail.com>:

> I have a question about how best to insert and manipulate the table with
> primary key id for better productivity. I need to insert data into the table
> and get last id.
>
> 1. First option to take counter Postgres SEQUENCE:
> INSERT INTO table (id, ...) VALUES ((SELECT nextval ('seq_table')), ...)
> RETURNING (SELECT currval ('seq_table')) AS id

Much simplier:

INSERT INTO table (name, email, salary) VALUES ('joe', 'joe@example.com',
100) RETURNING id;

Cheers,
  -Mike

--
Michał Roszka
mike@if-then-else.pl



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

Предыдущее
От: -
Дата:
Сообщение: The best option to insert data with primary id
Следующее
От: mike@if-then-else.pl
Дата:
Сообщение: Re: The best option to insert data with primary id