gorm
gorm copied to clipboard
Is it possible to turn off getting the last inserted id?
Your Question
If returning id is turned off, and the model contains an ID field, lastInsertId will be read by default; eg: driver postgres WithoutReturning: true
gorm.Model contain ID field
The document you expected this should be explained
Expected answer
Is it possible to turn off this feature?
We no longer support this feature, refer to https://github.com/go-gorm/postgres/issues/177#issuecomment-1522815541 Does anyone else need to support this feature? I hope to get more feedback. To support this feat, a configuration can be added to disable LastInsertId for drivers.
Maybe we can use field permission to disable the LastInsertId feature?
What are the scenarios? Can you describe it in detail? @ppanphper My understanding is
- Some databases do not support either
Returningsyntax orLastInsertIDqueries, in which case we need to disable them at the driver level LastInsertIDcauses other problem in some cases, so we need to disable it, in which case we can provide field permission disable or driver level disable. https://github.com/go-gorm/gorm/issues/6047
@a631807682
eg: distributed pgsql database dws;
For distributed database dws, if you want to return id, sql cannot be pushed down to DN, which affects performance.
If possible, it is best to support control at the driver and field levels; in fact, it is also possible to restrict the characteristics of the default primary key of id.
I am facing the same problem, I try to operate aws redshift, which can't support returning id, when I disable it , it return an error: "LastInsertId is not supported by this driver".
May I take this one?
May I take this one?
Assigned to you, thanks.
is there any update on this issue @e1esm ? I'm also facing same problem for redshift.
I try to operate aws redshift, which can't support returning id, when I disable it , it return an error: "LastInsertId is not supported by this driver".
If this issue is not fixed, I would do it in 7 days. @e1esm @a631807682
Need reviewers. @a631807682