實際上"::"是調用CAST函數的。究竟哪些欄位之間可以進行資料轉換呢?
這個問題只要研究一下cast函數就能夠得到答案。cast函數的資訊在系統pg_cast表裡面管理。
通過查詢我們可以得到現階段可以轉換的類型對照表如下:
源類型 轉換目標類型
int8 int2
int8 int4
int8 float4
int8 float8
int8 numeric
int2 int8
int2 int4
int2 float4
int2 float8
int2 numeric
int4 int8
int4 int2
int4 float4
int4 float8
int4 numeric
float4 int8
float4 int2
float4 int4
float4 float8
float4 numeric
float8 int8
float8 int2
float8 int4
float8 float4
float8 numeric
numeric int8
numeric int2
numeric int4
numeric float4
numeric float8
int4 bool
bool int4
int8 oid
int2 oid
oid int8
int8 regproc
int2 regproc
regproc int8
int8 regprocedure
int2 regprocedure
regprocedure int8
int8 regoper
int2 regoper
regoper int8
int8 regoperator
int2 regoperator
regoperator int8
int8 regclass
int2 regclass
regclass int8
int8 regtype
int2 regtype
regtype int8
int8 regconfig
int2 regconfig
regconfig int8
int8 regdictionary
int2 regdictionary
regdictionary int8
text regclass
varchar regclass
bpchar text
bpchar varchar
char text
char bpchar
char varchar
name text
name bpchar
name varchar
text char
bpchar char
varchar char
text name
bpchar name
varchar name
char int4
int4 char
abstime date
abstime time
abstime timestamp
abstime timestamptz
reltime interval
date timestamp
date timestamptz
time interval
time timetz
timestamp abstime
timestamp date
timestamp time
timestamp timestamptz
timestamptz abstime
timestamptz date
timestamptz time
timestamptz timestamp
timestamptz timetz
interval reltime
interval time
timetz time
lseg point
path point
path polygon
box point
box lseg
box polygon
box circle
polygon point
polygon path
polygon box
polygon circle
circle point
circle box
circle polygon
inet cidr
int8 bit
int4 bit
bit int8
bit int4
cidr text
inet text
bool text
text xml
cidr varchar
inet varchar
bool varchar
varchar xml
cidr bpchar
inet bpchar
bool bpchar
bpchar xml
bpchar bpchar
varchar varchar
time time
timestamp timestamp
timestamptz timestamptz
interval interval
timetz timetz
bit bit
varbit varbit
numeric numeric