Insert into a table with only a SERIAL

From: <felix(at)crowfix(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Insert into a table with only a SERIAL
Date: 2000-06-25 21:39:50
Message-ID: 14678.31782.627040.169981@crowfix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am pretty much self taught using SQL, and I suspect that my problem
here is trying to do something silly. I have since changed my tables
and avoided the problem, but I am curious as to why this happens, and
it's remotely possible I have even found a bug or two.

I created a table with only a sequence:

CREATE TABLE aaa (
id SERIAL,
);

I can't insert into aaa unless I pass a value; these don't work:

insert into aaa;
insert into aaa values ();
insert into aaa () values ();

But this does:

insert into aaa values (1);

except that the value inserted is not known to the sequence.
(** This seems a bug to me **)

This also works:

insert into aaa values (nextval('aaa_id_seq'));

but sort of defeats the purpose of using a type SERIAL rather than
hand rolling my own sequence.

--
... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
Felix Finch: scarecrow repairman & rocket surgeon / felix(at)crowfix(dot)com
GPG = E987 4493 C860 246C 3B1E 6477 7838 76E9 182E 8151 ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Gotts 2000-06-25 21:55:40 SQL INSERT bug with 6.5.3 and 7.0.2
Previous Message lincy lin 2000-06-25 03:23:38 More OO Support