Here it is mentioned that, "the data types smallserial
, serial
and bigserial
are not true types, but merely a notational convenience for creating unique identifier columns." Everywhere in the documentation they are all in lowercase except in this example
CREATE TABLE tablename (
colname SERIAL
);
Usually, keywords are written in uppercase, but cannot find serial
in the list of PostgreSQL keywords. So how should I write SERIAL
or serial
?
CodePudding user response:
SQL is case-insensitive (unless from the edge case where you quote object names, but this isn't the case here), so from a functional perspective you can write serial
or SERIAL
, or even Serial
or sErIAL
if you particularly want to (but seriously - don't).
Now this becomes a question of style, so my recommendation would be to match styles and keep your scripts consistent. If you uppercase your NUMERIC
and VARCHAR
columns, use SERIAL
, but if you have lowercase numeric
s and varchar
s, you should also have lowercase serial
s.
Personally I prefer uppercasing them, but that's just me.
Note that identity columns are a better alternative these days (GENERATED ALWAYS AS IDENTITY
).