Generated columns (PostgreSQL)
See original GitHub issueProblem
Postgres generated columns are currently not supported. That’s not a big deal, since we can always declare them as regular columns in the schema.prisma
. The only flaw is we need to declare them as optional, otherwise the client will always complain about them missing in the create input. This means the generated type field will always be “nullable”, when it’s actually not.
Suggested solution
Introduce a custom schema attribute ( ex @generated
) to mark a column as a postgres generated column. This way it will not be included in the create input type but it will also be not null in the model type.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:28
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Documentation: 15: 5.3. Generated Columns - PostgreSQL
A generated column is a special column that is always computed from other columns. Thus, it is for columns what a view is...
Read more >New In PostgreSQL 12: Generated Columns - pgDash
PostgreSQL 12 comes with a new feature called generated columns. Other popular RDBMSes already support generated columns as “computed columns” or “virtual ...
Read more >PostgreSQL Generated Always: Generate Computed Columns
A generated column is a unique column that is always computed from other existing columns. You cannot insert data into generated column but...
Read more >How to Create a Generated Column in PostgreSQL
In PostgreSQL, a generated column is a special column that is always computed from other columns. A generated column doesn't have a fixed ......
Read more >An Overview of Generated Columns for PostgreSQL
A Generated Column is a special column in a table that contains data automatically generated from other data within the row. The content...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: issue created https://github.com/prisma/prisma/issues/14799
@ryanmt I’ve just run into this after upgrading to Prisma 4 - these unwanted (+invalid!)
DROP DEFAULT
migrations were not being generated previously, so now I’ve hit a blocker preventing me creating new migrations.Are you using Prisma v4 also? Could you possibly share more about your workaround?
~~
In my
schema.prisma
(worked for the past months with Prisma v3):A previous custom migration in my migrations history results in the following schema in Postgres (which has been working fine):
Upgrading to Prisma v4 now generates these new
DROP DEFAULT
migrations that fail with error:I think you can already use
@default(dbgenerated())
here to specify that field is computed. We already support that. https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#dbgeneratedWhat we don’t do here is automatically add this for computed fields when we introspect so that is something that we should do. cc @do4gr