Re: OID - insert statement

Поиск
Список
Период
Сортировка
От Doug McNaught
Тема Re: OID - insert statement
Дата
Msg-id m3heoa79nj.fsf@varsoon.denali.to
обсуждение исходный текст
Ответ на OID - insert statement  (paul simdars <psimdars@lisco.com>)
Список pgsql-general
paul simdars <psimdars@lisco.com> writes:

> Many tables I am creating have IDs associated with the row.  I'm
> wondering what the syntax is for a new id in an insert statement.

Using OIDs for primary keys is a bad idea.  Here's the way it's
usually done:

CREATE TABLE mytable (
  id SERIAL PRIMARY KEY,
  name TEXT
);

INSERT INTO mytable (name) VALUES ('Name of first');
SELECT currval('mytable_id_seq');  -- yields last 'id' value inserted

See the docs for the SERIAL data type, and for CREATE SEQUENCE on
which it's based.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

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

Предыдущее
От: "Peter Darley"
Дата:
Сообщение: Re: A Replication Idea
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: Help with a plpgsql function