From 77b37c3551c20c2e1cf0f76def9f9a24e4191d73 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 11 Apr 2022 11:57:18 +0200 Subject: [PATCH] PostgreSQL: Support text comparsion for int/enum columns At the moment Icinga DB Web doesn't know the column types, so it sends SQL queries with LIKE operators for all suggestions in the search bar, which fails for numeric and enum types on PostgreSQL. To support this, the LIKE operator (internally translated to ~~) is overloaded. Note that this is only a temporary solution until Icinga DB Web provides column type support. --- schema/pgsql/schema.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 95486b34..0010daa0 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -161,6 +161,24 @@ BEGIN END; $$; +/* At the moment Icinga DB Web doesn't know the column types, + so it sends SQL queries with LIKE operators for all suggestions in the search bar, + which fails for numeric and enum types on PostgreSQL. + To support this, the LIKE operator (internally translated to ~~) is overloaded. + Note that this is only a temporary solution until Icinga DB Web provides column type support. + */ +CREATE OR REPLACE FUNCTION anynonarrayliketext(anynonarray, text) + RETURNS bool + LANGUAGE plpgsql + IMMUTABLE + PARALLEL SAFE + AS $$ + BEGIN + RETURN $1::TEXT LIKE $2; + END; + $$; +CREATE OPERATOR ~~ (LEFTARG=anynonarray, RIGHTARG=text, PROCEDURE=anynonarrayliketext); + CREATE TABLE host ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL,