Without having to do it manually (which I’m open to implementing if no other options exist), is there a way in either PostgreSQL or MySQL to have an automatic counter/field that decrements instead of increments?
For a variety of reasons in a current application, it would be nice to know how many more entries (from a datatype point of view) can still be added to a table just by looking at the most-recently-added record, rather than subtracting the most recent ID from the max for the datatype.
So, is there an “AUTO_DECREMENT” or similar for either system?
You have to do a bit of manual configuration in PostgreSQL but you can configure a sequence like that:
I suppose it would be equivalent to create the table with a
serialcolumn and then alter the auto-generated sequence.Now if I insert some rows I get example_id counting down from 5. If I try to insert more than 5 rows, I get
nextval: reached minimum value of sequence "example_seq" (1)