Skip to content
Advertisement

postgresql ERROR: syntax error at or near “PRIMARY”

I’m new to PostgreSQL. I’ve been trying to create tables in a database but some queries give weird errors. the first snippet throws a syntax error but when I add “serial” on the problematic column the error is resolved. Should all primary keys auto-increment in PostgreSQL?

This works added serial constraint on songplay_id

Advertisement

Answer

Should all primary keys auto-increment in PostgreSQL?

No, not necessarily.

In the first statement you are not specifying a data type for the column, if you don’t want it to be an auto increment, simply use integer:


Note that serial is not a “constraint”, it’s a data type definition which is a shortcut for an integer column that takes its default value from a sequence.

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