Skip to main content

转换

某些数据类型可以隐式或显式地转换为其他类型。

  • Implictly cast to: 值可以自动转换为目标类型。
  • Assigned to: 值在插入到目标类型的列时可以自动转换。
  • Explictly cast to: 只有在使用 cast 函数或 :: 操作符时,值才能转换为目标类型。
From typeImplictly cast toAssigned toExplictly cast to
booleanvarchar
integer
smallintinteger
bigint
numeric
real
double
rw_int256
varchar
integerbigint
numeric
real
double
rw_int256
smallintboolean
bigintnumeric
real
double
rw_int256
smallint
integer
varchar
numericreal
double
smallint
integer
bigint
varchar
realdoublesmallint
integer
bigint
numeric
varchar
doublesmallint
integer
bigint
numeric
real
varchar
varcharboolean
smallint
integer
bigint
numeric
real
double
date
timestamp
timestamp with time zone
time
interval
bytea
jsonb
rw_int256
datetimestamp
timestamp with time zone
varchar
timestamptimestamp with time zonevarchar
date
time
timestamp with time zonevarchar
date
timestamp
time
timeintervalvarchar
intervalvarchar
time
byteavarchar
jsonbboolean
smallint
integer
bigint
numeric
real
double
varchar
rw_int256varchar

:::注意

如果嵌套的表达式和类型是可以转换的,那么 struct 之间就可以进行显式或隐式转换。

:::