postgres8.3以后,字段数据之间的默认转换取消了。如果需要进行数据变换的话,在postgres数据库中,我们可以用"::"来进行字段数据的类型转换。实际上"::"是调用CAST函数的。究竟哪些字段之间可以进行数据转换呢?

   这个问题只要研究一下cast函数就能够得到答案。cast函数的信息在系统pg_cast表里面管理。

通过查询我们可以得到现阶段可以转换的类型对照表如下:

源类型            转换目标类型

int8int2
int8int4
int8float4
int8float8
int8numeric
int2int8
int2int4
int2float4
int2float8
int2numeric
int4int8
int4int2
int4float4
int4float8
int4numeric
float4int8
float4int2
float4int4
float4float8
float4numeric
float8int8
float8int2
float8int4
float8float4
float8numeric
numericint8
numericint2
numericint4
numericfloat4
numericfloat8
int4bool
boolint4
int8oid
int2oid
oidint8
int8regproc
int2regproc
regprocint8
int8regprocedure
int2regprocedure
regprocedureint8
int8regoper
int2regoper
regoperint8
int8regoperator
int2regoperator
regoperatorint8
int8regclass
int2regclass
regclassint8
int8regtype
int2regtype
regtypeint8
int8regconfig
int2regconfig
regconfigint8
int8regdictionary
int2regdictionary
regdictionaryint8
textregclass
varcharregclass
bpchartext
bpcharvarchar
chartext
charbpchar
charvarchar
nametext
namebpchar
namevarchar
textchar
bpcharchar
varcharchar
textname
bpcharname
varcharname
charint4
int4char
abstimedate
abstimetime
abstimetimestamp
abstimetimestamptz
reltimeinterval
datetimestamp
datetimestamptz
timeinterval
timetimetz
timestampabstime
timestampdate
timestamptime
timestamptimestamptz
timestamptzabstime
timestamptzdate
timestamptztime
timestamptztimestamp
timestamptztimetz
intervalreltime
intervaltime
timetztime
lsegpoint
pathpoint
pathpolygon
boxpoint
boxlseg
boxpolygon
boxcircle
polygonpoint
polygonpath
polygonbox
polygoncircle
circlepoint
circlebox
circlepolygon
inetcidr
int8bit
int4bit
bitint8
bitint4
cidrtext
inettext
booltext
textxml
cidrvarchar
inetvarchar
boolvarchar
varcharxml
cidrbpchar
inetbpchar
boolbpchar
bpcharxml
bpcharbpchar
varcharvarchar
timetime
timestamptimestamp
timestamptztimestamptz
intervalinterval
timetztimetz
bitbit
varbitvarbit
numericnumeric
05-11 15:09