Coding Bits
May 13th, 2024



The same person that taught me about LATERIAL SQL queries also showed me the BIGSERIAL type, which is an automatically incrementing integer column.

I don't know why I didn't see this before. The AUTOINCREMENT option in MySQL was one of the things I missed when I started using PostgreSQL. I guess I just assumed that one had to explicitly create a sequence and include calls to nextval() when inserting things into a PostgreSQL table, and that was "just how it was done."

After reading the docs on this type, it looks like this is still case here too, but PostgreSQL will take this action on for you. That's why "type" is in quotes above, since BIGSERIAL is not really a type, per se. It's more like a helper around the integer types that would automatically create the sequence for you, and configures the column to call nextval() as the default value.
Still, this is quite useful to know, and results in less SQL that I'll have to write, which is always a bonus. One more for the toolbox.