pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jose' Soares Da Silva <sferac@bo.nettuno.it>
To: The Web Administrator <wwwadmin@wizard.ca>
Cc: PGsql <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] How to handle a requirement for nextval
Date: Tue, 19 May 1998 09:50:07 +0000 (UTC)
Message-ID: <Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com> (raw)
In-Reply-To: <35609B0F.52A63C2@wizard.ca>

On Mon, 18 May 1998, The Web Administrator wrote:

> I am still struggling on a few issues, have got my first little database
> up and running, and am quite happy with PostGres, but I cannot figure
> out how to create a table which can have a field that autoincrements..
> I am sure that somewhere in the oid terminology it is built in, but I
> want to have a counter on some table entries..  ie...
> CREATE TABLE clothing_type (
>       type_id INT NOT NULL,
>       description TEXT,
>       for_sex CHAR
> );
> INSERT INTO clothing_type (
>    description,
>    for_sex
> ) VALUES (
>    'pants',
>    'm'
> );
> 
> What I want is that the Primary Key (Only Key) be type_id, and int, and
> the first item that I insert should have type_id as '1', next will be
> '2'  etc..
> I could have every insert into this table include a type_id, but that
> seems unessary.
> Can I have something like default='nextval' ?
   CREATE SEQUENCE serial START 101;

   CREATE TABLE distributors (
          did      DECIMAL(03) DEFAULT NEXTVAL('serial'),
	  name     VARCHAR(40)
	  );

    -- Use sequence in insert:
    --
    INSERT INTO distributors VALUES (NEXTVAL('serial'));
                                                            Jose'




view thread (7+ messages)  latest in thread

Message-ID: <Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com>
Permalink:  ../Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com/
Also on:    postgresql.org/message-id/Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: sferac@bo.nettuno.it, wwwadmin@wizard.ca
  Subject: Re: [SQL] How to handle a requirement for nextval
  In-Reply-To: <Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com>
  References: <35609B0F.52A63C2@wizard.ca> <Pine.LNX.3.96.980519094533.412B-100000@proxy.bazzanese.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox