Reputation: 339
I have a table named dept_registration it has a column dept_code so I have to make this field auto-generate but in a specific pattern.
example:- test0001 test0002 test0003 test0004
the "test" should be appended before number automatically after insertion
Upvotes: 0
Views: 134
Reputation: 248295
The column definition could be
dept_code text DEFAULT 'test' || lpad(nextval('myseq')::text, 4, '0')
where myseq
is a sequence.
You will get in trouble once the counter reaches 10000...
Upvotes: 2