Skip site navigation (1) Skip section navigation (2)

Re: autoincrement question

From: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
To: "Jack Albright" <jack(at)mobiusnm(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: autoincrement question
Date: 2008-01-07 21:12:36
Message-ID: 264855a00801071312o27fc6cc8h4d5ddeca6b6acb7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Jan 7, 2008 3:57 PM, Jack Albright <jack(at)mobiusnm(dot)com> wrote:

> I'm new to the list and new to postgreSQL.
> I usually work in mySQL.
> I'm using NaviCat to manipulate my postgreSQL db.
>
> QUESTION:
> What is the best way for a novice like me to  make my  primary key ID
> column   auto-increment?  It is a basic integer column.
>
>  Also, do I need to set a default value  for my primary keys?
>
> In MySQL (using phpMyAdmin) it's a simple matter of checking a
> checkbox. What is the recommended way to do this in postgres?
>

A column of type "serial" will be a simple integer column that gets its
values from a sequence, which will be automatically created.  In other
words:

create table junktable (
     pk1 serial primary key
);

will get you what you want.  Check out the docs for the "serial" column
type.

Sean

In response to

Responses

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2008-01-07 22:39:39
Subject: Re: autoincrement question
Previous:From: Jack AlbrightDate: 2008-01-07 20:57:50
Subject: autoincrement question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group