RE: autoincrement???

From: Joshua Jore <moomonk(at)daisy-chan(dot)org>
To: Kevin Bullaughey <kevin(at)gambitdesign(dot)com>
Cc: Markus Jais <mjais(at)web(dot)de>, <pgsql-general(at)postgresql(dot)org>
Subject: RE: autoincrement???
Date: 2001-07-14 10:41:56
Message-ID: Pine.BSO.4.33.0107140540320.17705-100000@aaieee.daisy-chan.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Huh, that's novel. I'd always written that as:

INSERT INTO address VALUES (nextval('some_seq'), 'mainstreet 12', 85253,
'munich', 'Germany');

where the difference is not using that extra 'SELECT' in the middle.

Josh

On Fri, 13 Jul 2001, Kevin Bullaughey wrote:

> one way to do this is with a sequence.
>
> CREATE SEQUENCE some_seq MINVALUE 1;
> CREATE TABLE address (
> address_id int PRIMARY KEY ,
> street VARCHAR(40),
> zipcode INT,
> city VARCHAR(40),
> country VARCHAR(40)
> );
> INSERT INTO address VALUES(select nextval('some_seq'), 'mainstreet 12',
> 85253, 'munich', 'Germany');
>
> in theory this should work but i didn't check it...it gives you the idea
> anyway.
>
> -kevin
>
> --------------------------------------------
> Kevin Bullaughey <kevin(at)gambitdesign(dot)com>
> Gambit Design Internet Services
>
> Integrated domain registration and
> web-based DNS management
>
> --- http://www.gambitdesign.com/dns.html ---
>
>
> > -----Original Message-----
> > From: pgsql-general-owner(at)postgresql(dot)org
> > [mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Markus Jais
> > Sent: Thursday, July 12, 2001 5:20 PM
> > To: pgsql-general(at)postgresql(dot)org
> > Subject: [GENERAL] autoincrement???
> >
> >
> > 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lamar Owen 2001-07-14 12:44:36 Re: Nusphere/MySQL-AB arguing
Previous Message Martijn van Oosterhout 2001-07-14 10:12:36 Need feedback on possible new feature