Re: OID - insert statement

From: Doug McNaught <doug(at)wireboard(dot)com>
To: paul simdars <psimdars(at)lisco(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: OID - insert statement
Date: 2002-02-21 22:27:44
Message-ID: m3heoa79nj.fsf@varsoon.denali.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

paul simdars <psimdars(at)lisco(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-02-21 22:28:11 Re: Help with a plpgsql function
Previous Message Peter Darley 2002-02-21 22:15:13 Re: A Replication Idea