select * from bucket where foo=bar order by field (xxx, “us”, “gb”, “es”) ?
I can’t find any documentation related to this, and if I try the above I get an error: “Number of arguments to function FIELD must be 2. - at end of input”
What I need is to be able to order the results in a specific order based on a list of values, not just ASC or DESC
WITH orderobj AS ({"us":1, "gb":2, "cn":3, "es":4})
SELECT b.*
FROM `bucket` AS b
WHERE b.foo = "bar"
ORDER BY orderobj.[b.country_code];
WITH orderobj AS ({"us":10, "gb":2, "cn":3, "es":4})
SELECT b.*
FROM [{ "app_name": "abc", "country_code": "us","type": "app" }, { "app_name": "abcus", "country_code": "us","type": "app" }, { "app_name": "abcd", "country_code": "gb","type": "app" }, { "app_name": "abce", "country_code": "es","type": "app" }, { "app_name": "abcf", "country_code": "cn","type": "app" }] AS b
WHERE b.type = "app"
ORDER BY orderobj.[b.country_code];
Still, something is not working I am getting a totally different order.
The order is correct but the results are sorted at the end. Do I need to define all the potential options, or is there a way to move them at the begining for the country codes which are not defined in sort object?