Felix H.
Felix H.

Reputation: 1112

Create Postgresql Default Auto Increment Sequence number based in ID concat with Current Date format

I want to get auto increment default sequence as CURRENT_TIMESTAMP (with 2 digits 'year' format) + ID (5 digits)...
Like this:
If current year is 2020,
2010001, 2010002, 2010003, ...

If current year is 2021,
2110001, 2110002, 2110003, ...

Please, help me out, and give me any idea.

Upvotes: 0

Views: 288

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246918

Use a normal sequence, set its value to 2010000, and at the beginning of 2021 set it to 2110000.

Upvotes: 1

Related Questions