Error With Auto_increment While Conneted To Postgres Via Psql And Putty
I'm getting this error in puTTY. Not sure why, looks right to me ... psql:pierre.sql:10: ERROR: syntax error at or near 'AUTO_INCREMENT' LINE 2: c_id INTEGER NOT NULL AUTO_INCRE
Solution 1:
auto_increment looks like something you'd use with MySQL.
But, here, it seems you are using PostgreSQL.
According to the datatype serial section of the manual, postgresql's equivalent of auto_increment is serial or bigserial.
Quoting that page :
The data types
serialandbigserialare not true types, but merely a notational convenience for setting up unique identifier columns (similar to theAUTO_INCREMENTproperty supported by some other databases).
Solution 2:
In Postgres 10 or later consider an IDENTITY column:
CREATETABLE customer(
c_id INTEGER GENERATED BYDEFAULTASIDENTITYPRIMARY KEY,
...
(PRIMARY KEY also makes it NOT NULL automatically.)
Details:
In Postgres 9.6 or older consider a serial like Pascal already suggested.
Works in pg 10 or later, too, but IDENTITY is generally superior.
Post a Comment for "Error With Auto_increment While Conneted To Postgres Via Psql And Putty"