Re: automatic insert of next sequence value? - Mailing list pgsql-general

From
Subject Re: automatic insert of next sequence value?
Date
Msg-id Pine.LNX.4.10.10010121322520.15718-100000@chapelperilous.net
Whole thread Raw
In response to automatic insert of next sequence value?  (J B Bell <jbbell@intergate.ca>)
List pgsql-general
On Thu, 12 Oct 2000, J B Bell wrote:

> I've recently started with pgsql after having used mysql.  Oddly, a problem
> the latter seems to have followed me.
>
> When I set up a field with a default value to use a sequence (with "nextval"),
> It doesn't work automatically.  Both using DBI and the pgsql cli, if I do
>
> INSERT INTO foo VALUES (NULL);
>
> or
>
> INSERT INTO foo VALUES ('');
>
> I get an error or null is inserted in the first case, if the field is set
> non-null, or a 0 in the second case.

It should auto-increment if you don't specify the field at all:

create sequence myseq;

create table mytable (
    id int4 PRIMARY KEY default nextval('myseq'),
    descr text
);

insert into mytable(descr) values ('some text');

Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
Is a tattoo real, like a curb or a battleship?  Or are we suffering in Safeway?


pgsql-general by date:

Previous
From: Aristide Aragon
Date:
Subject: Error creating tables.
Next
From: J B Bell
Date:
Subject: Re: automatic insert of next sequence value? - Thank you!