KingbaseES ALTER TABLE 中 USING 子句的用法

using子句用于在修改表字段类型的时候,进行显示的转换类型。

1.建表

create table t(id integer);

2.插入数据

insert into t select generate_series(1,10);

3.把id列类型修改为varchar

test=# alter table t alter id type varchar;
ALTER TABLE

因为integervarchar有隐式的转换,所以可以自动转换过去。

4.把id列类型改回integer

test=#  alter table t alter id type integer;
错误:  字段 "id" 不能自动转换成类型 integer
提示:  您可能需要指定"USING id::integer"。

在oracle模式下有varcharinteger的cast函数,所以不会报错。上述错误是在pg模式下产生的。

5.使用Using子句进行强制类型转换

test=# alter table t alter id type integer using id::integer;
ALTER TABLE

转换类型的时候有隐含类型转换的时候,会自动转换,如果没有,那么就必须使用using指定一下转换规则。

posted @   KINGBASE研究院  阅读(299)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2021-07-02 KingbaseES 如何实现Oracle pipelined 功能
点击右上角即可分享
微信分享提示