Is there a way I can use Case When statements in a Javascript API query?
n
Needle
05/25/2022, 4:03 AM
Hello @AlanK!
This thread has been automatically created from your message in #843999948717555735 a few seconds ago.
We have already mentioned the @User so that they can see your message and help you as soon as possible!
Want to unsubscribe from this thread?
Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates.
Want to change the title?
Use the ``/title`` command!
We have solved your problem?
Click the button below to archive it.
g
garyaustin
05/25/2022, 4:08 AM
If you need an SQL case then you certainly can do an rpc function. But for basic equivalent in JS could you not just select the column and then do a switch on the result (or map operation if multiple rows)? I guess it depends on your actual use and complexity.
n
Needle
05/25/2022, 4:08 AM
AlanK (2022-05-25)
a
AlanK
05/25/2022, 4:16 AM
Thanks for the prompt reply - I have implemented a switch solution. But I was wondering if there was something I was missing that would allow me to do it in the query. I need to filter NULL attributes and return empty arrays or empty strings for some fields.
g
garyaustin
05/25/2022, 4:38 AM
Basically you have select and then filters on the js side. If a combination of filters does not work, then you either post process the result, or if it makes sense for performance move it to an rpc function. I only do rpc if I have to because of limiting number of items downloaded or security, as I find it easier to maintain logic code in javascript than sql scripts in functions, but that is really a personal preference.
a
AlanK
05/25/2022, 5:44 AM
Thank you
n
Needle
05/25/2022, 5:44 AM
Thread was archived by @AlanK. Anyone can send a message to unarchive it.