From: | Jason Earl <jdearl(at)yahoo(dot)com> |
---|---|
To: | Markus Jais <mjais(at)web(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: autoincrement??? |
Date: | 2001-07-13 02:38:45 |
Message-ID: | 20010713023845.26608.qmail@web10008.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
You could either try:
CREATE TABLE address (
address_id int SERIAL,
street VARCHAR(40),
zipcode INT,
city VARCHAR(40),
country VARCHAR(40)
);
Or you could do the same thing yourself manually with:
CREATE sequence address_id_seq;
CREATE TABLE address (
address_id int PRIMARY KEY DEFAULT
nextval('address_id_seq'),
street VARCHAR(40),
zipcode INT,
city VARCHAR(40),
country VARCHAR(40)
);
I personally like the latter as it is slightly more
flexible. Plus, I often create large SQL scripts to
rebuild the database schema when I am developing and
the longer way reminds me that I need to drop the
sequence before creating the table :).
Jason
--- Markus Jais <mjais(at)web(dot)de> wrote:
> hi
> I have the following problem:
>
> I create the following table:
>
> CREATE TABLE address (
> address_id int PRIMARY KEY ,
> street VARCHAR(40),
> zipcode INT,
> city VARCHAR(40),
> country VARCHAR(40)
> );
>
> Now, I want the address_id to get incremented
> every time I insert a value into the table.
>
> for example:
> INSERT INTO address VALUES('mainstreet 12', 85253,
> 'munich', 'Germany')
> ;
> without specifying a value for the id.
>
> a friend told me, that this works in MySQL with
> something
> like "auto_increment". I do not know much about
> MySQL so I do not
> know if this is true.
>
> Can you please tell me, how to do this in
> postgresql????
>
> thanks a lot
> regards
> markus
>
> --
> Markus Jais
> http://www.mjais.de
> info(at)mjais(dot)de
> The road goes ever on and on - Bilbo Baggins
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please
> send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org
> so that your
> message can get through to the mailing list cleanly
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Ed Loehr | 2001-07-13 05:03:43 | Re: Visual Modeling programs |
Previous Message | Justin Clift | 2001-07-13 02:33:14 | Re: Visual Modeling programs |