一直追随使用Greenplum数据库的朋友们,在之前低版本的Greenplum中如果我们想把布尔类型直接用显示转换的方式转为文本类型(例如:select '1'::bool::text;),那么你可能会碰壁,只能自己创建转换函数做一下间接转换。
但是,随着Greenplum的升级,官方已经对这种转换需求做了支持:
之前我们进行转换时,可能会报如下的错误:
gpadmin=# select boolout('1')::text;
ERROR: cannot cast type cstring to text
LINE 1: select boolout('1')::text;
^
gpadmin=# select '1'::bool::text;
ERROR: cannot cast type boolean to text
LINE 1: select '1'::bool::text;
^
目前在数据库中,我们只需要显示的定义一下转换即可:
postgres=# select '1'::bool;
bool
------
t
(1 row)
postgres=# select '1'::bool::text;
text
------
true
(1 row)