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
Sometimes it would be nice to have a default value operator in case a field is null.
In case a field is missing, I can use obj.value("field", 0.0). There is no pendant for null values though and I would have to write something like auto val = obj["field"].is_null() ? 0.0 : obj["field"].get<double>() which gets ugly when used for several fields.
I could imagine that an operator for such situation could be very handy. I would imagine something like the following:
// inspired from SQLdouble value = obj.ifnull("field", 0.0); // if obj["field"] is null, return 0.0// probably not much of a use case but why not mention the more generic SQL inspired operatordouble value = obj.coalesce("field1", "field2", 0.0); // takes the first non-null value among obj["field1"], obj["field2"], and 0.0
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Sometimes it would be nice to have a default value operator in case a field is null.
In case a field is missing, I can use
obj.value("field", 0.0)
. There is no pendant for null values though and I would have to write something likeauto val = obj["field"].is_null() ? 0.0 : obj["field"].get<double>()
which gets ugly when used for several fields.I could imagine that an operator for such situation could be very handy. I would imagine something like the following:
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions