Postgresql 中文操作指南

10.6. SELECT Output Columns #

前几节给出的规则将导致将非 unknown 数据类型分配给 SQL 查询中的所有表达式,除了作为 SELECT 命令的简单输出列出现的未指定类型文字除外。例如,在

The rules given in the preceding sections will result in assignment of non-unknown data types to all expressions in an SQL query, except for unspecified-type literals that appear as simple output columns of a SELECT command. For example, in

SELECT 'Hello World';

中没有任何内容可以识别字符串文字应该是什么类型。在这种情况下,PostgreSQL 将回退以将文字的类型解析为 text

there is nothing to identify what type the string literal should be taken as. In this situation PostgreSQL will fall back to resolving the literal’s type as text.

SELECTUNION(或 INTERSECTEXCEPT)构造的一个分支时,或者当它出现在 INSERT …​ SELECT 中时,此规则不适用于从属规则优先。在第一种情况下,可以从另一个 UNION 分支中获取未指定类型文字的类型,或者在第二种情况下可以从目标列中获取。

When the SELECT is one arm of a UNION (or INTERSECT or EXCEPT) construct, or when it appears within INSERT …​ SELECT, this rule is not applied since rules given in preceding sections take precedence. The type of an unspecified-type literal can be taken from the other UNION arm in the first case, or from the destination column in the second case.

RETURNING 列表为此目的视同 SELECT 输出列表。

RETURNING lists are treated the same as SELECT output lists for this purpose.

Note

在 PostgreSQL 10 之前,此规则并不存在,并且_SELECT_ 输出列表中未指定类型的文字将保留 unknown 类型。这带来了各种不良后果,因此它进行了更改。

Prior to PostgreSQL 10, this rule did not exist, and unspecified-type literals in a SELECT output list were left as type unknown. That had assorted bad consequences, so it’s been changed.