↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3
历史版本PostgreSQL 9.1 已于 2016 年 10 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本。

45.10. pg_cast #

目录 pg_cast 存储数据类型转换路径,包括内建的路径和用CREATE CAST定义的路径。

需要注意的是,pg_cast并不表示系统知道如何执行的所有类型转换,它只包括那些不能从某些通用规则推导出的转换。例如,一个域及其基础类型之间的转换并未显式地在pg_cast中展示。另一个重要的例外是“自动的基于 I/O 的类型转换”,它们通过数据类型自己的 I/O 函数来转换成(或者转换自)text或其他字符串类型,这些转换也没有显式地在pg_cast中表示。

表 45.10. pg_cast 列

Name Type References Description
castsource oid pg_type.oid OID of the source data type
casttarget oid pg_type.oid OID of the target data type
castfunc oid pg_proc.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的项有着不同的原类型和目标类型,并且有一个接收多于一个参数的函数,那么它会在一个步骤中完成从一种类型到另外一种类型的转换并应用一个长度转换。如果没有这样的项,使用一个类型修改器的转换涉及两个步骤,一个是在数据类型之间转换,另外一个是应用修改器。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。