Auto Increment

Started by Nonameover 25 years ago11 messagesgeneral
Jump to latest
#1Noname
postgres@flipper.webdevelop.net

Is there a way set a primary key to Auto Increment like you can
with MySQL?

Thanks..

#2Oliver Elphick
olly@lfix.co.uk
In reply to: Noname (#1)
Re: Auto Increment

postgres@flipper.webdevelop.net wrote:

Is there a way set a primary key to Auto Increment like you can
with MySQL?

CREATE TABLE junk (id SERIAL PRIMARY KEY, ...etc...)

The SERIAL data type is an INTEGER coupled with a sequence which is
created automatically.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"And they said, Believe on the Lord Jesus Christ, and
thou shalt be saved, and thy house." Acts 16:31

#3Brett W. McCoy
bmccoy@chapelperilous.net
In reply to: Noname (#1)
Re: Auto Increment

On Tue, 26 Dec 2000 postgres@flipper.webdevelop.net wrote:

Is there a way set a primary key to Auto Increment like you can
with MySQL?

See the documentation on CREATE SEQUENCE, and also on CREATE TABLE and the
SERIAL type.

[An aside: this is something definitely that qualifies as a frequently
asked question, as this is like the 4th time in a week this question has
been asked. Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Hanson's Treatment of Time:
There are never enough hours in a day, but always too many days
before Saturday.

#4Bruce Momjian
bruce@momjian.us
In reply to: Brett W. McCoy (#3)
Re: Auto Increment

On Tue, 26 Dec 2000 postgres@flipper.webdevelop.net wrote:

Is there a way set a primary key to Auto Increment like you can
with MySQL?

See the documentation on CREATE SEQUENCE, and also on CREATE TABLE and the
SERIAL type.

[An aside: this is something definitely that qualifies as a frequently
asked question, as this is like the 4th time in a week this question has
been asked. Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

I don't think so. Doesn't everyone know the location of the FAQ?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#5Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#4)
Re: Auto Increment

On Tue, 26 Dec 2000, Bruce Momjian wrote:

See the documentation on CREATE SEQUENCE, and also on CREATE TABLE and the
SERIAL type.

[An aside: this is something definitely that qualifies as a frequently
asked question, as this is like the 4th time in a week this question has
been asked. Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

I don't think so. Doesn't everyone know the location of the FAQ?

Perhaps not -- this is what I am wondering. Is it sent to subscribers as
part of a welcome message? At any rate, this particular question I think
has now qualified for the FAQ, at the very least! Or maybe even a section
in the FAQ for people coming over from MySQL...

It is already in the FAQ, right?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#6Brett W. McCoy
bmccoy@chapelperilous.net
In reply to: Bruce Momjian (#4)
Re: Auto Increment

On Tue, 26 Dec 2000, Bruce Momjian wrote:

See the documentation on CREATE SEQUENCE, and also on CREATE TABLE and the
SERIAL type.

[An aside: this is something definitely that qualifies as a frequently
asked question, as this is like the 4th time in a week this question has
been asked. Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

I don't think so. Doesn't everyone know the location of the FAQ?

Perhaps not -- this is what I am wondering. Is it sent to subscribers as
part of a welcome message? At any rate, this particular question I think
has now qualified for the FAQ, at the very least! Or maybe even a section
in the FAQ for people coming over from MySQL...

-- Brett

PS. Got your book, Bruce. Nice job!
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
"The pyramid is opening!"
"Which one?"
"The one with the ever-widening hole in it!"
-- The Firesign Theatre

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#4)
Re: Auto Increment

Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

I don't think so. Doesn't everyone know the location of the FAQ?

Undoubtedly not :-( ... but it's unlikely that a routine posting would
help to dispel cluelessness, either. More likely it'd just waste space
in the archives.

At one time Marc was arranging for the list bot to append automatic
tags to all postings. I'd be in favor of an automatic tag that read
something like

list administrivia: majordomo@hub.org
Postgres FAQs: http://...

Suggestions anyone? (Keep in mind that brevity is the soul of wit
here...)

regards, tom lane

#8Brett W. McCoy
bmccoy@chapelperilous.net
In reply to: Bruce Momjian (#5)
The FAQ

On Wed, 27 Dec 2000, Bruce Momjian wrote:

Perhaps not -- this is what I am wondering. Is it sent to subscribers as
part of a welcome message? At any rate, this particular question I think
has now qualified for the FAQ, at the very least! Or maybe even a section
in the FAQ for people coming over from MySQL...

It is already in the FAQ, right?

Doh!

OK, now that my foot is out of my mouth... perhaps a gentle reminder to
some of the newer folks that a lot of questions asked are answered in the
FAQ already, and if you don't know where the FAQ is, go to
http://www.postgresql.org/docs/faq-english.html (there are also FAQs in
German, Japanese and Korean).

And don't mind me... been a long evening of coding...

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
An aphorism is never exactly true; it is either a half-truth or
one-and-a-half truths.
-- Karl Kraus

#9Brett W. McCoy
bmccoy@chapelperilous.net
In reply to: Tom Lane (#7)
Re: Auto Increment

On Wed, 27 Dec 2000, Tom Lane wrote:

At one time Marc was arranging for the list bot to append automatic
tags to all postings. I'd be in favor of an automatic tag that read
something like

list administrivia: majordomo@hub.org
Postgres FAQs: http://...

Suggestions anyone? (Keep in mind that brevity is the soul of wit
here...)

I think that's a good idea... one line in a tag may save many packets of
questions that don't need to be asked on the list if they have already
been answered. :-)

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Premature optimization is the root of all evil.
-- D.E. Knuth

#10Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#7)
List metadata tags (was Re: Auto Increment)

Tom Lane writes:

At one time Marc was arranging for the list bot to append automatic
tags to all postings. I'd be in favor of an automatic tag that read
something like

list administrivia: majordomo@hub.org
Postgres FAQs: http://...

Suggestions anyone? (Keep in mind that brevity is the soul of wit
here...)

RFC 2369 <http://www.faqs.org/rfcs/rfc2369.html&gt;

This essentially says that you add headers like this to every mail:

List-Help: <mailto:autoconf-request@gnu.org?subject=help>
List-Post: <mailto:autoconf@gnu.org>
List-Subscribe: <http://mail.gnu.org/mailman/listinfo/autoconf&gt;,
<mailto:autoconf-request@gnu.org?subject=subscribe>
List-Id: Discussion list for the autoconf build system <autoconf.gnu.org>
List-Unsubscribe: <http://mail.gnu.org/mailman/listinfo/autoconf&gt;,
<mailto:autoconf-request@gnu.org?subject=unsubscribe>
List-Archive: <http://mail.gnu.org/pipermail/autoconf/&gt;

(There's isn't anything for FAQ, but there could be a link on the archive
page maybe.)

If a mail with these headers shows up in my mail client I get a link "This
message contains email list management information." that I can click on
and which in turn explains to me what an email list is and then allows me
to click on the URLs above. Very nice.

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/

#11Noname
postgres@flipper.webdevelop.net
In reply to: Brett W. McCoy (#3)
Re: Auto Increment

I had looked everywhere to find the answer to this question. Now that I
look at the FAQ again I see it in there. I tryed searching the FAQ for
"auto increment" when it turns out to be "auto-increment" on the FAQs
page. Being a MySQL user who was dead ended and had no choice but to find
a new database with Transactions or something simliar because of MySQL's
limitations I had several questions that seemed difficult to find during
the switchover.

1. Auto increment - now serial datatype

2. 'SHOW TABLES' in mysql - now '\d' (I got lucky to stumble apon this.)

3. 'DESCRIBE' in mysql - now '\d tablename' (same as above.)

As more people realize MySQL's limitations I think there will be more
people making the switchover. As a result I'm sure many people find
themselves asking the same questions I did. I would recommend these 3
things be easy to find the the FAQ for MySQL familiar users.

My 2 cents...

On Tue, 26 Dec 2000, Brett W. McCoy wrote:

Show quoted text

On Tue, 26 Dec 2000 postgres@flipper.webdevelop.net wrote:

Is there a way set a primary key to Auto Increment like you can
with MySQL?

See the documentation on CREATE SEQUENCE, and also on CREATE TABLE and the
SERIAL type.

[An aside: this is something definitely that qualifies as a frequently
asked question, as this is like the 4th time in a week this question has
been asked. Would posting a FAQ list on a regular basis to the list be
helpful for things like this, like is done on the Perl newsgroups?]

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Hanson's Treatment of Time:
There are never enough hours in a day, but always too many days
before Saturday.