How to use postgres default values as common default?

267    Asked by DipikaAgarwal in SQL Server , Asked on Oct 3, 2022

 How can I specify the default value for a column in the DDL? I was pretty sure that the following method worked a while ago:

CREATE TABLE test

(
  col_1 CHAR(12) NOT NULL,
  col_2 INTEGER  NOT NULL WITH DEFAULT,
  col_3 CHAR(12) NOT NULL WITH DEFAULT
);

I would just like to define that the DB should use the default value for the column data type (like in my example above), without specifying which value exactly.


Answered by Diya tomar

You should specify what the postgres default values are. If I remember correctly the DEFAULT should be before NOT NULL:


CREATE TABLE test

( col_1 CHAR(12) NOT NULL,
  col_2 INTEGER DEFAULT 0 NOT NULL,
  col_3 CHAR(12) DEFAULT '' NOT NULL
);


Your Answer

Interviews

Parent Categories