Maximum value for default Ecto :id in PostGres

When you create a standard Ecto schema for PostGres and you don’t specify anything special about the primary key, it defines it as an :integer, but how big is it? My GUI is giving me conflicting info… is it a PostGres integer or a bigint? PostgreSQL: Documentation: 9.1: Numeric Types

The schema itself won’t define what is in the database but the migration will. For a migration it will map to bigint. One easy way to check is to run a migration then \d table in a postgres client

2 Likes

My memory is extremely fuzzy but I think in Elixir the integer type does not have a fixed byte size and grows if it needs to. Which is why it can be used for smallint, int, bigint, etc…

\d yep, thanks!!

FWIW, on Ecto 3.x the generated :id column defaults to bigserial:

That will show as bigint in GUIs etc, since it’s not a type but a shorthand for “bigint + sequence”

1 Like

That’s interesting - thanks! When I finally got into my db and remembered all the \d commands, I’m seeing bigint for my id column (Ecto 3.9.1). What threw me was that my GUI (Beekeeper Studio – my favorite PostGres GUI so far) seemed confused – one place listed the field as int8 and another as uuid (?).