From: | <bmccoy(at)chapelperilous(dot)net> |
---|---|
To: | J B Bell <jbbell(at)intergate(dot)ca> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: automatic insert of next sequence value? |
Date: | 2000-10-12 17:25:48 |
Message-ID: | Pine.LNX.4.10.10010121322520.15718-100000@chapelperilous.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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?
From | Date | Subject | |
---|---|---|---|
Next Message | K Parker | 2000-10-12 18:48:04 | Re: PostgreSQL book |
Previous Message | Aristide Aragon | 2000-10-12 17:23:18 | Error creating tables. |