| From: | "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net> | 
|---|---|
| To: | Vipin Samtani <Vipin(dot)Samtani(at)cornell(dot)edu> | 
| Cc: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Auto-increment Numeric Primary keys | 
| Date: | 2000-06-18 22:20:52 | 
| Message-ID: | Pine.LNX.4.10.10006181809390.2487-100000@chapelperilous.net | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
On Sun, 18 Jun 2000, Vipin Samtani wrote:
> How can I auto-increment numeric primary keys? So on a table called
> "Test1" with fields "ID" and "Name" when I do an INSERT, I only type
> 
> INSERT INTO Test1 values ('Bob');
> 
> instead of
> 
> INSERT INTO Test1 values (1, 'Bob');
> 
> Is this implemented in PostgreSQL 7?
You'll want to use the serial type:
CREATE TABLE Test1 (mykey SERIAL, Name varchar(10));
You will need to specify the fields when you insert:
INSERT INTO Test1(Name) Values('Bob');
However, take a look at using sequences (which is what the serial type
uses underneath).  They can give you a good bit of flxibility in terms of
starting and ending numbers, amount of increment, and so on.
Brett W. McCoy                        
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
Everything I like is either illegal, immoral or fattening.
		-- Alexander Woollcott
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2000-06-19 04:10:45 | Re: int8 and hash index | 
| Previous Message | Mike Mascari | 2000-06-18 22:08:53 | Re: Auto-increment Numeric Primary keys |