question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use IDENTITY columns in PG10+

See original GitHub issue

Problem

When I define a new entity/table in my schema using id Int @id @default(autoincrement()) the generator returns "id" SERIAL.

Suggested solution

The recommended solution is to use the SQL standard GENERATED BY DEFAULT AS IDENTITY.

Additional context

https://wiki.postgresql.org/wiki/Don’t_Do_This#Don.27t_use_serial

Nice to have

A way to migrate from SERIAL to IDENTITY columns.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:21
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
janpiocommented, Jan 19, 2022

No, that is what this feature request is about.

2reactions
weavdalecommented, Dec 2, 2021

Any update on this? It would be nice to use best practices for auto incrementing fields in Postgres.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL 10 identity columns explained - EDB
Dropping the identity property of an existing column is easy: ALTER TABLE test_new ALTER COLUMN id DROP IDENTITY; You cannot accidentally make ...
Read more >
What are Identity Columns?
An identity column has a start value, an increment, a maximum value, a minimum value, and a cycle option. ... ... The definition...
Read more >
Waiting for PostgreSQL 10 – Identity columns - Depesz
Identity columns This is the SQL standard-conforming variant of PostgreSQL's serial columns. It fixes a few usability issues that serial ...
Read more >
How to obtain last inserted Identity value with PG10 ... - GitHub
Hi, PG10 introduces identity fields, all great, except... how to obtain the inserted value in the row? The examples I've seen: INSERT INTO ......
Read more >
PostgreSQL Identity Column
PostgreSQL allows you a table to have more than one identity column. Like the SERIAL , the GENERATED AS IDENTITY constraint also uses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found