1

I'm looking to plot the equivalent of the SQL query

SELECT column_3
FROM my_object
WHERE map_layer is not null
AND column_1 > column_2;

Using this answer I can see where the expression should go (in the filter) and that I can combine multiple filters but not how to compare values.

Which gives me

"source-layer": "my_object",
        "filter": ['all',["==", ["typeof", ["get", "col_3"]], "string"],[another expression here]]

1 Answer 1

2

I would interpret 'greater of two values' as the (PG) SQL equivalent of

SELECT GREATEST(column_1, column_2)
...

However, the query you posted would simply translate to

"filter": [">", ["get", "column_1"], ["get", "column_2"]]

or

"filter": [
  "all", 
  ["!=", ["get", "map_layer"], "<NULL_VALUE>"],
  [">", ["get", "column_1"], ["get", "column_2"]
]

filter for (show only) all features where ["map_layer" is not "NULL_VALUE" and] "column_1" is greater than "column_2"

Note that you will need to fill in "<NULL_VALUE>" with the actual value that you get returned (e.g. "" for an empty string);

2
  • Thank you for the pointer this got me to what I needed, I had to explicitly get col3 as it styling is categorical "filter": ["all",["==", ["typeof", ["get", "col_3"]], "string"],[">",["get","column_1"],["get","column_2"]]], Commented Oct 10, 2019 at 10:41
  • Just seen your edit, much more elegant than the above! Also thanks for raising awareness of PG GREATEST Commented Oct 10, 2019 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.