Home > Software design >  Is serial considered a keyword or a numeric type?
Is serial considered a keyword or a numeric type?

Time:01-13

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 numerics and varchars, you should also have lowercase serials.
Personally I prefer uppercasing them, but that's just me.

Note that identity columns are a better alternative these days (GENERATED ALWAYS AS IDENTITY).

  • Related