Is there a native FQL function that will return the first non-null value? Similar to Coalesce in SQL? I have a few variables set using
Let and I want to find the first that is non-nullable. I suppose I could put them all in an array and use a combination of
Select but wondered if there was an easier way?
Nulls sort last, unless you set
reverse: true: Data types - Fauna Documentation
Check the first value returned, if it is
null, there are no non-null values to return, otherwise, there you go.
ok cool, I thought this would probably be the case. Was hoping there was something built in, but that’s fine, this will work just fine!
Sort comes from using sets, such as an index. That won’t help you use values in a
Let expression. As you noted, you’d need to use
c: "a value!",
[Var("a"), Var("b"), Var("c"), Var("d")],
But if you can rework your query to use an index, you’ll be able to find the first non-null value for any number of values.