Menu
Squawk LogoSquawk LogoSquawkDocsRules
Quick StartGitHub
Squawk LogoSquawk LogoSquawk
  • Docs
  • Rules
  • Quick Start
  • GitHub
  • General
    • Quick Start
    • Applying migrations safely
    • CLI
    • GitHub Integration
    • Web Frameworks
    • Postgres locks and further reading
    • Troubleshooting
  • Rules
    • Rules Overview
    • adding-field-with-default
    • adding-foreign-key-constraint
    • adding-not-nullable-field
    • adding-serial-primary-key-field
    • ban-char-field
    • ban-drop-database
    • changing-column-type
    • constraint-missing-not-valid
    • disallowed-unique-constraint
    • prefer-big-int
    • prefer-bigint-over-int
    • prefer-bigint-over-smallint
    • prefer-identity
    • prefer-robust-stmts
    • prefer-text-field
    • prefer-timestamptz
    • renaming-column
    • renaming-table
    • require-concurrent-index-creation
    • require-concurrent-index-deletion

prefer-identity

problem#

Serial types make permissions and schema management difficult. Identity columns are standard SQL and have more features and better usability.

solution#

Instead of:

create table app.users
(
id bigserial
)

Use:

create table app.users
(
id bigint generated by default as identity primary key
)

links#

  • https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial
  • https://www.enterprisedb.com/blog/postgresql-10-identity-columns-explained
Edit this page
Previous
« prefer-bigint-over-smallint
Next
prefer-robust-stmts »
  • problem
  • solution
  • links

Docs

  • Quick Start
  • Rules

More

  • GitHub
  • Changelog
  • Help
Copyright © 2023 Squawk Authors.