postgres数据库中的数据转换
postgres8.3以后,字段数据之间的默认转换取消了。如果需要进行数据变换的话,在postgres数据库中,我们可以用"::"来进行字段数据的类型转换。实际上"::"是调用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 |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。