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
And I wanted to update a table adding dynamic sets based on whether if such pointers have value or not (without setting them to null).
I tried:
// decoded a MyStruct into "ms"query:=goqu.Update("table").Set(
goqu.Record{
"a": ms.A,
"b": ms.B,
"c": ms.C
}
)
In case A has a value, but B and C are nil, this will populate column "table.a", but will also populate with NULL the columns "table.b" and "table.c" which is not what I want. In this case I would expect only A to be updated.
But in case B and C have values, only C gets updated (the latest Set overrides previous Set statements, instead of being aggregated).
Ultimately the question is how to write an update query, having a struct, so that only the non-nil pointers are set? Or am I going for the wrong approach? 🙃
The text was updated successfully, but these errors were encountered:
This might be more a question rather than a bug or feature request.
I have an scenario where I have a struct with 3 pointers like:
And I wanted to update a table adding dynamic sets based on whether if such pointers have value or not (without setting them to null).
I tried:
In case A has a value, but B and C are
nil
, this will populate column "table.a", but will also populate withNULL
the columns "table.b" and "table.c" which is not what I want. In this case I would expect only A to be updated.I also tried:
But in case B and C have values, only C gets updated (the latest
Set
overrides previousSet
statements, instead of being aggregated).Ultimately the question is how to write an update query, having a struct, so that only the non-nil pointers are set? Or am I going for the wrong approach? 🙃
The text was updated successfully, but these errors were encountered: