Insert into a table with only a SERIAL

Поиск
Список
Период
Сортировка
От
Тема Insert into a table with only a SERIAL
Дата
Msg-id 14678.31782.627040.169981@crowfix.com
обсуждение исходный текст
Ответы Re: Insert into a table with only a SERIAL
Список 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@crowfix.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Michael Fraley
Дата:
Сообщение: ERROR: fmgr_info: function 19104: cache lookup failed
Следующее
От: John Gotts
Дата:
Сообщение: SQL INSERT bug with 6.5.3 and 7.0.2