How to nullfill variable (equivalent of SQL coalesce)
I keep running into the use case of wanting to create a variable that is the first non-empty value of a series of other variables. For example for some final variable X:
- I want X to be the first non-empty value of variables A, B, and C
- So if A = 2, B = null, C = 1 then I want X = 2
- If A = null, B = null, C = 1 then I want X = 1
- If A = null, B = 3, C = 1 then I want X = 3
Is there a way to achieve that with the existing Xano variable + filter logic?
Answers
-
As far as I know, Xano can do coalesce only in the "query all records" function.
However, if you want to do something similar with variables, I would suggest to do the following.
Create an array with the values of your variables. Insert them in the order you want to be parsed. Then apply the filter "filter_empty" to the array, which returns a new array with only the entries that are not empty ("", null, 0, [], {}). Then apply the filter "first" to get the first value of the new array. It should return what you are looking for.
-
Thanks @arturosanz! That's a clever idea. I was able to figure this out another way though given Xano has released conditional set filters that do basically what I'm saying. By using first_notempty I was able to mimic coalesce.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback