转换
某些数据类型可以隐式或显式地转换为其他类型。
- Implictly cast to: 值可以自动转换为目标类型。
- Assigned to: 值在插入到目标类型的列时可以自动转换。
- Explictly cast to: 只有在使用
cast
函数或::
操作符时,值才能转换为目标类型。
From type | Implictly cast to | Assigned to | Explictly cast to |
---|---|---|---|
boolean | varchar | integer | |
smallint | integer bigint numeric real double rw_int256 | varchar | |
integer | bigint numeric real double rw_int256 | smallint | boolean |
bigint | numeric real double rw_int256 | smallint integer varchar | |
numeric | real double | smallint integer bigint varchar | |
real | double | smallint integer bigint numeric varchar | |
double | smallint integer bigint numeric real varchar | ||
varchar | boolean smallint integer bigint numeric real double date timestamp timestamp with time zone time interval bytea jsonb rw_int256 | ||
date | timestamp timestamp with time zone | varchar | |
timestamp | timestamp with time zone | varchar date time | |
timestamp with time zone | varchar date timestamp time | ||
time | interval | varchar | |
interval | varchar time | ||
bytea | varchar | ||
jsonb | boolean smallint integer bigint numeric real double | varchar | |
rw_int256 | varchar |
:::注意
如果嵌套的表达式和类型是可以转换的,那么 struct 之间就可以进行显式或隐式转换。
:::