历史版本。 PostgreSQL 9.2 已结束支持。 2017-11-09. 请参阅 当前版本手册.
45.10. pg_cast #
目录 pg_cast 存储数据类型转换路径,包括内建路径和用户自定义路径。
需要注意的是,pg_cast并不表示系统知道如何执行的所有类型转换,它只包括那些不能从某些通用规则推导出的转换。例如,一个域及其基础类型之间的转换并未显式地在pg_cast中展示。另一个重要的例外是“自动的基于 I/O 的类型转换”,它们通过数据类型自己的 I/O 函数来转换成(或者转换自)text或其他字符串类型,这些转换也没有显式地在pg_cast中表示。
表 45.10. pg_cast 列
| Name | Type | References | Description |
|---|---|---|---|
castsource | oid | | OID of the source data type |
casttarget | oid | | OID of the target data type |
castfunc | oid | | The OID of the function to use to perform this cast. Zero is stored if the cast method doesn't require a function. |
castcontext | char | Indicates what contexts the cast can be invoked in.
e means only as an explicit cast (using
CAST or :: syntax).
a means implicitly in assignment
to a target column, as well as explicitly.
i means implicitly in expressions, as well as the
other cases.
| |
castmethod | char | Indicates how the cast is performed.
f means that the function specified in the castfunc field is used.
i means that the input/output functions are used.
b means that the types are binary-coercible, thus no conversion is required.
|
在pg_cast里列出的类型转换函数必须总是以转换的源类型作为它的第一个参数类型,并且返回转换的目标类型作为它的结果类型。一个类型转换函数最多有三个参数。如果出现了第二个参数,必须是integer类型;它接受与目标类型关联的修饰词,如果没有,就是 -1。如果出现了第三个参数,那么必须是boolean类型;如果该类型转换是一种明确的转换,那么它接受true,否则接受false。
在pg_cast里创建一条源类型和目标类型相同的记录是合理的,只要相关联的函数接受多过一个参数。这样的记录代表“长度转换函数”,它们把该类型的值转换为对特定的类型合法的值。
如果一个pg_cast的项有着不同的原类型和目标类型,并且有一个接收多于一个参数的函数,那么它会在一个步骤中完成从一种类型到另外一种类型的转换并应用一个长度转换。如果没有这样的项,使用一个类型修改器的转换涉及两个步骤,一个是在数据类型之间转换,另外一个是应用修改器。