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

前端 未结 6 1675
滥情空心
滥情空心 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:46

    It's a common misconception that you can denormalise like this for performance. Use date_trunc('month', date) for your queries and add an index expression for this if you find it running slow.

提交回复
热议问题