Skip to content
Advertisement

Why is the “multiple default values” error when creating a postgresql table?

I am trying to create a table with this query:

Error:

I thought that maybe a mistake due to the parameter NOT NULL, but removing it did not change anything. Most of the problems that I found on the Internet with such an error are due to Django, or other ORMs, but this is not my case, so I could not get around this.

Advertisement

Answer

serial is not a real type, but an alias which includes a default.

From the docs….

The data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases). In the current implementation, specifying:

is equivalent to specifying:

So all that nextval and not null is unnecessary. serial does it for you.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement