RSS Amplifier

Cole's blog · Oct 26, 2024

Using PostgreSQL Identity Columns in Ecto SQL

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

When working with PostgreSQL and Elixir’s Ecto ORM, you are likely using SERIAL columns for auto-incrementing primary keys. However, since PostgreSQL 10 (released in October 2017), there’s a better way: IDENTITY columns. Why Identity Columns? Identity columns (GENERATED AS IDENTITY) are part of the SQL Standard and are the recommended approach for auto-incrementing keys in modern…

When working with PostgreSQL and Elixir’s Ecto ORM, you are likely using SERIAL columns for auto-incrementing primary keys. However, since PostgreSQL 10 (released in October 2017), there’s a better way: IDENTITY columns. Why Identity Columns? Identity columns (GENERATED AS IDENTITY) are part of the SQL Standard and are the recommended approach for auto-incrementing keys in modern Postgres. While I won’t dive into why SERIAL columns should be avoided (check out Stop using SERIAL in Postgres for details), let’s explore how to use IDENTITY columns with Ecto.

Read on /2024/10/26/ecto-sql-identity-columns/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.