I have a dynamic string that is created in one of the following ways:
var q = "FROM Table SELECT sum(1), count(2), avg(3) where x='y'
var q = "SELECT min(1), max(2), average(3) FROM Table where z='x' since y days ago
The values after the select statement can vary from 1 to 10. I am trying to develop a method to always extract the selected values into an array, but I am struggling with the variable nature (the dynamically constructed string and the varying number of selects).
In essence, I want the final result to look like this:
['sum(1)', 'count(2)', 'avg(3)']
Currently, my approach involves the following code, but it relies on the string being organized in a specific way (always starting with SELECT
and having a where
clause after the fields to extract):
let splitQ = q.match(".*SELECT(.*)where");
let selects = splitQ[1].trim().split(",");