I am using Postgres 9.1 and would like to create a sequence which I can use as primary key and which should look like this:
| entity_id_seq |
-----------------
| X0001 |
| X0002 |
....
| X0123 |
and nextval( 'entity_id_seq' ) would return 'X0124'.
Any idea’s how and if this is possible with pure Postgres?
Many thanks!
Something like this should be fine:
Create the sequence:
Create a function, or not:
Now check if it works:
Now you can create the table using the above function:
or just without function with the simple query from the function: