PostgreSQL's Itches and Scratches: Sequences
Posted on August 12, 2010
Sequences in PostgreSQL is a classic example where less means more. What is wrong with MySQL's AUTOINCREMENT flag on a column? Sure, it is not as general as sequences in PostgreSQL but be honest with yourself and count how many times you have used a table for which AUTOINCREMENT would not have been enough. I used it once but removed with the next commit because the sequence I needed was not exactly a sequence and the Python code which created the next number was very easy to write and read.
Compare:
nextval('mailing_template_id_seq'::regclass
AUTOINCREMENT
How about Django:
relation "mailing_outgoingmessage_id_seq" does not exist LINE 1: SELECT CURRVAL('"mailing_outgoingmessage_id_seq"')
Why do I even get this error? Where is the abstraction? (This has been actually fixed.)
The problem I have with sequences in PostgreSQL is they would bite exactly when you do not care how PostgreSQL does it. They are not part of table but exist in their own space with their own names, permissions, ownerships and what have you not.
I am sorry. Easy things should be easy. Sequences are not easy. An acceptable compromise could be having both AUTOINCREMENT and sequences at the same time in PostgreSQL - for those who believe they need them.
I feel this article is a part of the series: why MySQL is better for web applications than PostgreSQL after all - no it really is.