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?
Comment From: a631807682
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.
Comment From: jinzhu
Maybe we can use field permission to disable the LastInsertId feature?
Comment From: a631807682
What are the scenarios? Can you describe it in detail? @ppanphper
My understanding is
1. Some databases do not support either Returning syntax or LastInsertID queries, in which case we need to disable them at the driver level
2. LastInsertID causes 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
Comment From: ppanphper
@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.
Comment From: yyystation
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".
Comment From: e1esm
May I take this one?
Comment From: a631807682
May I take this one?
Assigned to you, thanks.
Comment From: Ajaysinh1290
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".