瀚高数据库中隐式转换的命令,错误******* is of type numeric but expression is of type boolean

        在java程序中提示一些错误时需要进行数据类型的更改,其中方法就是更改程序中的数据类型、或者在sql中 使用  :: 数据类型,进行转换、再或者就是开启数据库的隐式类型转换。下面就是瀚高数据中隐式类型转换的设计方法以及使用方法、

1、需要在设置的数据库中执行以下命令 
-- 查看隐式类型转换的语句
select
	castsource::regtype,
	casttarget::regtype,
	castcontext,
	castfunc
from
	pg_cast
where
	castsource = 'boolean'::regtype;

执行的效果如下:

2、创建一个隐式类型转换的函数
--创建隐式类型转换方法
--其中booleanToSmallint(boolean) 建议是根据转换的类型进行创建 括号中的是需要转换的数据类型
-- smallint -> 可以更换为需要转换的数据类型
create
	or replace function booleanToSmallint(boolean) returns smallint as $$ begin if $1 = true then return 1;
else return 0;
end if;
end;
$$ language plpgsql;

 执行效果:这里是因为我创建过所有受影响行数没有变化

3、创建后在执行一下命令
-- 创建隐式转换函数
-- smallint 更换为上一条命令时创建的数据类型
-- booleanToSmallint(boolean) 与上面同理
create
	cast(
		boolean as smallint
	) with function booleanToSmallint(boolean) as implicit;

 执行效果:这里是因为我创建过所以提示存在

 

4、如果创建错误可以执行
drop cast(boolean as numeric);
 
drop function booleanToNumeric;

  • 14
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值