From 4c9cb7aa2cc7a9db580c1e8e13d2cadb07725959 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Wed, 23 Oct 2024 14:58:24 +0200 Subject: [PATCH] Add Compare Macros --- chsql/src/chsql_extension.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/chsql/src/chsql_extension.cpp b/chsql/src/chsql_extension.cpp index 090b4b4..3cd229b 100644 --- a/chsql/src/chsql_extension.cpp +++ b/chsql/src/chsql_extension.cpp @@ -127,6 +127,13 @@ static DefaultMacro chsql_macros[] = { {DEFAULT_SCHEMA, "JSONType", {"json"}, {{nullptr, nullptr}}, R"(json_each(json))"}, {DEFAULT_SCHEMA, "JSONExtractKeys", {"json"}, {{nullptr, nullptr}}, R"(json_object_keys(json))"}, {DEFAULT_SCHEMA, "JSONExtractValues", {"json"}, {{nullptr, nullptr}}, R"(json_each_text(json))"}, + // -- Compare Macros + {DEFAULT_SCHEMA, "equals", {"a", "b"}, {{nullptr, nullptr}}, R"((a = b))"}, + {DEFAULT_SCHEMA, "notEquals", {"a", "b"}, {{nullptr, nullptr}}, R"((a <> b))"}, + {DEFAULT_SCHEMA, "less", {"a", "b"}, {{nullptr, nullptr}}, R"((a < b))"}, + {DEFAULT_SCHEMA, "greater", {"a", "b"}, {{nullptr, nullptr}}, R"((a > b))"}, + {DEFAULT_SCHEMA, "lessOrEquals", {"a", "b"}, {{nullptr, nullptr}}, R"((a <= b))"}, + {DEFAULT_SCHEMA, "greaterOrEquals", {"a", "b"}, {{nullptr, nullptr}}, R"((a >= b))"}, // -- Misc macros {DEFAULT_SCHEMA, "generateUUIDv4", {nullptr}, {{nullptr, nullptr}}, R"(toString(uuid()))"}, {DEFAULT_SCHEMA, "parseURL", {"url", "part", nullptr}, {{nullptr, nullptr}}, R"(CASE part WHEN 'protocol' THEN REGEXP_EXTRACT(url, '^(\w+)://') WHEN 'domain' THEN REGEXP_EXTRACT(url, '://([^/:]+)') WHEN 'port' THEN REGEXP_EXTRACT(url, ':(\d+)') WHEN 'path' THEN REGEXP_EXTRACT(url, '://[^/]+(/.+?)(\?|#|$)') WHEN 'query' THEN REGEXP_EXTRACT(url, '\?([^#]+)') WHEN 'fragment' THEN REGEXP_EXTRACT(url, '#(.+)$') END)"},