Answer the question
In order to leave comments, you need to log in
Update multiple models go pg bulk update time.Time?
The problem is that when updating one model, everything works, and when trying to update several models, an error occurs about the impossibility to update the date (time.Time go object
)
type Object struct {
ID string `sql:",notnull"`
StartAt time.Time `sql:",notnull"`
Body string `sql:",notnull"`
}
objects := []*Object
for _, object := range objects {
object.StartAt = time.Now()
}
for _, object := range objects {
_, err := s.db.Model(&objects).Column("start_at", "body").Update()
if err != nil {
return err
}
}
_, err := s.db.Model(&objects).Column("start_at", "body").Update()
Answer the question
In order to leave comments, you need to log in
I tried to run your code with updating several models - everything seems to be working fine.
And log what SQL query go-pg generates and show us.
I managed
UPDATE "objects" AS "object" SET "start_at" = _data."start_at", "body" = _data."body"
FROM (VALUES ('2019-05-16 21:14:19.579398+00:00:00'::timestamptz, 'body', '1'),
('2019-05-16 21:14:19.579398+00:00:00'::timestamptz, 'body', '2'))
_data("start_at", "body", "id") WHERE "object"."id" = _data."id"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question