加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql 类型转化时遇到的问题

发布时间:2020-12-13 16:41:47 所属栏目:百科 来源:网络整理
导读:postgres=# alter table test alter config type jsonb ; ERROR: column "config" cannot be cast automatically to type jsonb HINT: Specify a USING jsonb to perform the conversion. 之前config 字段类型为 hstore,怎么才能转化呢,如下三种方式都可以
postgres=# alter table test alter config type jsonb;
ERROR:  column "config" cannot be cast automatically to type jsonb 
HINT:  Specify a USING jsonb to perform the conversion.

之前config 字段类型为 hstore,怎么才能转化呢,如下三种方式都可以:
第一种

alter table test alter config type jsonb using config::jsonb;

第二种

alter table test alter config type jsonb using(config::jsonb);

第三种

alter table test alter config type jsonb using cast(config as jsonb);

#test case
select cast('12' as int);
select '12'::int;

如果是int 类型变更为 varchar 可以不用显示的using 方式去变更,这个与类型的强弱有关系, 如 5/2.0 其实计算机会把5先转成与2.0一样的浮点类型,然后再做除法, 如果想要5/2.0得到整数,则这样才能获得:(int)5/2.0 。 注:5/2.0的类型转化是C语言例子

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读