Search code examples
postgresqlddl

What do "constant", "expression", and "sequence" represent in a DEFAULT clause?


Currently creating my PostgreSQL tables through Postico, and I came across this field for when creating new columns. It is called DEFAULT and its default value is no default. You can select constant, expression, and sequence as options, though.

What exactly do these mean?


Solution

  • The manual on CREATE TABLE:

    DEFAULT default_expr

    The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). The data type of the default expression must match the data type of the column.

    The default expression will be used in any insert operation that does not specify a value for the column. If there is no default for a column, then the default is null.

    constant and expression should be clear now. sequence is a special feature to make it a serial column:

    More details on the page @mu provided: