Merge pull request #461 from Icinga/postgres-integer-like

PostgreSQL: Support LIKE for integer/enum columns
This commit is contained in:
Julian Brost 2022-05-13 16:17:42 +02:00 committed by GitHub
commit 09af3c8184
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,