Re: automatic insert of next sequence value?

From: Tomas Berndtsson <tomas(at)nocrew(dot)org>
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:16:39
Message-ID: 80g0m2dloo.fsf@junk.nocrew.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

J B Bell <jbbell(at)intergate(dot)ca> writes:

> 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.
>
> Of course without this, a good part of the convenince of auto-incrementing is
> defeated. I can work around it by looking up the appropriate value, but then
> I need to do locking as well, which is likely slower and definitely more
> annoying.

Doing:

INSERT INTO foo(col1, col2, col4) VALUES(val1, val2, val4);

will do what you want, given that col3 is the auto-incrementing
column. I.e. tell PostgreSQL to only set the other columns.

Tomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alfred Perlstein 2000-10-12 17:22:10 Re: automatic insert of next sequence value?
Previous Message Jean-Christophe Boggio 2000-10-12 17:07:15 Re[2]: Comments on earlier age() post.