I want to create a code for a table in postgresql.
The model could looks like:
event {id, code, name, created\_by}
The code will start at E0001 and finish at E9999. The idea is to check at insert, if there's no code generate it, else insert the provided code.
I assume I have to use a trigger, but I don't know how to generate that code with that sequence and check if exists or not.
Help.