IF function in RQL

You can now write more complex queries in RQL using the new IF function.

Syntax:

IF(bool_expr, value_if_true, value_if_false)

For example, to chart Javascript error occurrences based on whether they happened immediately upon page load, shortly after load, a while after load, or long after load, you can use IF with the client.runtime_ms property as follows:

SELECT
  IF(client.runtime_ms < 1000, '1_load_to_1second',
    IF(client.runtime_ms < 60*1000, '2_1second_to_1minute',
      IF(client.runtime_ms < 60 * 60 * 1000, '3_1minute_to_1hour',
        IF(client.runtime_ms >= 60 * 60 * 1000, '4_1hour_and_up', 'unknown')))) time_on_page,
  COUNT(*)
FROM item_occurrence
WHERE framework = 'browser-js'
  AND timestamp > unix_timestamp() - 3600
GROUP BY 1
ORDER BY 1

Screenshot 2019-07-05 12.15.50.png