How to set a Postgresql default value datestamp like 'YYYYMM'?

前端 未结 6 1826
滥情空心
滥情空心 2021-02-05 00:09

As title, how can I set a table\'s column to have the default value the current year and month, in format \'YYYYMM\', like 200905 for today?

6条回答
  •  甜味超标
    2021-02-05 00:56

    Just in case Milen A. Radev doesn't get around to posting his solution, this is it:

    CREATE TABLE foo (
        key     int PRIMARY KEY,
        foo     text NOT NULL DEFAULT TO_CHAR(CURRENT_TIMESTAMP,'YYYYMM')
    );
    

提交回复
热议问题