0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

I tested and it worked like this ... SELECT setval('seq_name', (CAST(TO_CHAR(now(), 'YY') || 10001 AS INTEGER)), FALSE)
I also thought another way ... Can I create that auto date concat sequence by using trigger for year by year?
That would be slower, and you still would have to reset the sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.