1、使用postgre账号进入到相应的模式下执行:

CREATE OR REPLACE FUNCTION boolean_to_smallint(b boolean) RETURNS smallint AS $$BEGINRETURN (b::boolean)::bool::int;END;$$LANGUAGE plpgsql;CREATE CAST (boolean AS smallint) WITH FUNCTION boolean_to_smallint(boolean) AS implicit;

 

2、测试:(is_leader字段为smallint类型)

UPDATE public."user"SET is_leader=TrueWHERE id='125';