-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
support VIRTUAL/GENERATED columns (eg Postgres STORED). Allow querying, never write. #12718
Copy link
Copy link
Open
Open
Copy link
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).
Description
Feature Description
In Postgres, STORED columns aren't updatable, but need to be read from db.
Is your feature request related to a problem? Please describe.
eg
total_amount NUMERIC(12, 2) NOT NULL GENERATED ALWAYS AS (amount * quantity) STORED,
gives
ERROR unhandledRejection column "total_amount" can only be updated to DEFAULT
Describe the solution you'd like
A new readOnly option in model, or a VIRTUAL/GENERATED column type (see comments)
total_amount: {
type: DataTypes.DOUBLE,
readOnly: true
},
This should be easy to implement. Here
https://github.com/sequelize/sequelize/blob/042cd693635ffba83ff7a2079974692af6f710a7/src/dialects/abstract/index.js
add
/* features specific to readOnly values */
readOnly: {
/* does the dialect require modification of insert queries when inserting */
identityInsert: false,
/* does the dialect support inserting default/null values */
defaultValue: false,
/* does the dialect support updating fields */
update: false
},
Why should this be in Sequelize
In databases, some fields are read-only. eg Postgres STORED columns. This might also be used for views in future.
Describe alternatives/workarounds you've considered
Using autoIncrement, but that doesn't work properly and it's not autoIncrement, it's a read-only column.
Feature Request Checklist
Is this feature dialect-specific?
- No. This issue is relevant to Sequelize as a whole.
- Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ
Would you be willing to implement this feature by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).