OID - insert statement

Started by paul simdarsabout 24 years ago3 messagesgeneral
Jump to latest
#1paul simdars
psimdars@lisco.com

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.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----

#2paul simdars
psimdars@lisco.com
In reply to: paul simdars (#1)
Re: OID - insert statement

In article <3C7401C5.87C5CA97@lisco.com>, "paul simdars"
<psimdars@lisco.com> wrote:

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.

I guess I figured this one out too. Each row inserted automatically
generates its own unique identifier.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----

#3Doug McNaught
doug@wireboard.com
In reply to: paul simdars (#1)
Re: OID - insert statement

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