Обсуждение: [GENERAL] serial type

Поиск
Список
Период
Сортировка

[GENERAL] serial type

От
Greg Beams
Дата:
I'm trying to create a table as such:

create table comment
(rec_id serial,
locale varchar(50),
...)

It creates correctly, telling me that it will create an implicit sequence
for the serial column, and an implicit index for the table.  But, when I
try to insert a record into the database (without specifying the value for
the rec_id column) I get the following error:

ERROR:  serial.nextval: sequence does not exist

Does anyone have any ideas (I'm not sure whether this belongs on this
list, or the pgsql-sql list)?

Thanks, Greg.

Greg Beams - gob@students.cs.mu.oz.au

I'M NOT OKAY, YOU'RE NOT OKAY--BUT, HEY, THAT'S OKAY.


Re: [GENERAL] serial type

От
Charles Tassell
Дата:
What is the syntax you are using for the insert?

This:

INSERT INTO comment VALUES (, 'Example');

or this

INSERT INTO comment (rec_id, locale) VALUES (, 'Example');

won't work.  You have to *specifically* leave out the sequence field in
your field list, like this:

INSERT INTO comment (locale) VALUES ('Example');

It works the same for any default value, which is basically what a sequence
is (type sequence = int default nextval('sequence') )

At 01:45 AM 9/28/99, Greg Beams wrote:
>I'm trying to create a table as such:
>
>create table comment
>(rec_id serial,
>locale varchar(50),
>...)
>
>It creates correctly, telling me that it will create an implicit sequence
>for the serial column, and an implicit index for the table.  But, when I
>try to insert a record into the database (without specifying the value for
>the rec_id column) I get the following error:
>
>ERROR:  serial.nextval: sequence does not exist
>
>Does anyone have any ideas (I'm not sure whether this belongs on this
>list, or the pgsql-sql list)?
>
>Thanks, Greg.
>
>Greg Beams - gob@students.cs.mu.oz.au
>
>I'M NOT OKAY, YOU'RE NOT OKAY--BUT, HEY, THAT'S OKAY.
>
>
>************
>