From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: How to autoincrement a primary key...
Date: Sat, 23 Sep 2006 00:12:00 +0200
Message-ID: <ef1n3g$ra2$1@sea.gmane.org> (raw)
In-Reply-To: <20060922192541.46464.qmail@web31815.mail.mud.yahoo.com>
References: <000001c6de7b$3a211c70$6501a8c0@laptop>
<20060922192541.46464.qmail@web31815.mail.mud.yahoo.com>
Richard Broersma Jr wrote on 22.09.2006 21:25:
>> I am sure this is simple, but I don't get it. I am new to PGSQL, coming from
>> MySQL - in mysql, you can autoincrement the primary key; in postgre, I am
>> not sure how to do this. I have read the documentation, and tried "nextval"
>> as the default - I have searched for the datatype SERIAL, but I am using
>> navicat and this datatype is not supported. Can someone tell me how to do
>> this - I just want the integer value for a primary key to autoincrement by
>> one.
>
> CREATE TABLE bar (id SERIAL PRIMARY KEY);
>
>
> Is just shorthand notation for:
>
> CREATE SEQUENCE foo START 1;
> CREATE TABLE bar (id integer PRIMARY KEY DEFAULT nextval('bar'));
>
Well the shorthand notation has a minor gotcha: you cannot drop the sequence
that has been created automatically. Only if you drop the column itself. Should
not be a problem, but it is a difference between a SERIAL PRIMARY KEY definition
and the "verbose" mode
Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: How to autoincrement a primary key...
In-Reply-To: <ef1n3g$ra2$1@sea.gmane.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox