You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using go-gorm with a Postgres 11 DB and facing an issue where I need to remove the RETURNING clause entirely when creating records. I just want to insert records and get nothing back. In go-pg I could use Returning("null") but I couldn't find a way to do it with GORM.
I have many relations on the database that doesn't support RETURNING statements, so when I try to insert records I get the error "ERROR: cannot perform INSERT RETURNING on relation X".
I tried creating the db connection with the parameter WithoutReturning: true. But then I get a different error "LastInsertId is not supported by this driver". It still tries to get the last inserted id anyway.
Thank you very much for your time!
The document you expected this should be explained
There should be a mention to the RETURNING statement on the "Create" section of the documentation and instructions on how to get rid of it if my query won't support.
Copying my Stackoferflow question, where I wrote with a simple code to demo the problem:
I'm using go-gorm with a postgres 11 DB and facing an issue where I need to remove the RETURNING clause entirely when creating records (that statement seems to be included by default). I just want to insert records and get nothing back, except for errors.
I have some complex relations on the database that won't support RETURNING statements, so when I try to insert like this: (made code simpler for brevity)
type Cargo struct {
Id int64 `gorm:"primaryKey"`
Name string
}
dsnString := fmt.Sprintf("host=%s ...")
db, _ := gorm.Open(postgres.New(postgres.Config{DSN: dsnString}), &gorm.Config{})
cargo := Cargo{Name: "test"}
db.Create(cargo)
I get the error "ERROR: cannot perform INSERT RETURNING on relation X".
I tried creating the db connection with the parameter WithoutReturning: true:
But then when I try db.Create(cargo) I get a different error: "LastInsertId is not supported by this driver". It seems to be still trying to get the last inserted id anyway.
In go-pg I could use db.Model(x).Returning("null").Insert(cargo) but I couldn't find a way to do it with go-gorm. Any help is greatly appreciated.
Your Question
I'm using go-gorm with a Postgres 11 DB and facing an issue where I need to remove the RETURNING clause entirely when creating records. I just want to insert records and get nothing back. In go-pg I could use Returning("null") but I couldn't find a way to do it with GORM.
I have many relations on the database that doesn't support RETURNING statements, so when I try to insert records I get the error "ERROR: cannot perform INSERT RETURNING on relation X".
I tried creating the db connection with the parameter WithoutReturning: true. But then I get a different error "LastInsertId is not supported by this driver". It still tries to get the last inserted id anyway.
Thank you very much for your time!
The document you expected this should be explained
There should be a mention to the RETURNING statement on the "Create" section of the documentation and instructions on how to get rid of it if my query won't support.
https://gorm.io/docs/create.html
Expected answer
A polite answer on how to create records when my DB is not supporting RETURNING statements would be great! =D
The text was updated successfully, but these errors were encountered: