-- 创建函数/操作符用于比较整数和布尔值 用于解决PostgreSQL 查询时报错 `operator does not exist: boolean = integer` 的问题
-- Create a function to compare integers and booleans to solve the problem of `operator does not exist: boolean = integer` when querying in PostgreSQL
CREATEORREPLACEFUNCTIONequal_int_bool(xint,ybool)
RETURNSBOOLEANAS$$
begin
returnx=y::int;
end;
$$LANGUAGEPLPGSQLIMMUTABLESTRICT;
-- 创建操作符 用于比较整数和布尔值 用于解决PostgreSQL 查询时报错 `operator does not exist: boolean = integer` 的问题
-- Create an operator to compare integers and booleans to solve the problem of `operator does not exist: boolean = integer` when querying in PostgreSQL
DO$$
BEGIN
IFNOTEXISTS(
SELECT1
FROMpg_operator
WHEREoprname='='AND
oprleft='integer'::regtypeAND
oprright='boolean'::regtype
)THEN
CREATEOPERATOR=(
leftarg=INTEGER,
rightarg=BOOLEAN,
procedure=equal_int_bool);
ENDIF;
END;
$$LANGUAGEplpgsql;
-- 创建函数/操作符用于比较整数和布尔值 用于解决PostgreSQL 查询时报错 `operator does not exist: boolean = integer` 的问题
-- Create a function to compare integers and booleans to solve the problem of `operator does not exist: boolean = integer` when querying in PostgreSQL
CREATEORREPLACEFUNCTIONequal_bool_int(xbool,yint)
RETURNSBOOLEANAS$$
begin
returnx::int=y;
end;
$$LANGUAGEPLPGSQLIMMUTABLESTRICT;
-- 创建操作符 用于比较整数和布尔值 用于解决PostgreSQL 查询时报错 `operator does not exist: boolean = integer` 的问题
-- Create an operator to compare integers and booleans to solve the problem of `operator does not exist: boolean = integer` when querying in PostgreSQL