SELECT output columns

更新时间:
复制 MD 格式

The type resolution rules described in the preceding sections assign a non-unknown data type to every expression in a SQL query — with one exception: unspecified-type literals that appear as simple output columns of a SELECT command.

For example:

SELECT 'Hello World';

Nothing in this statement constrains what type the string literal should be, so the database falls back to resolving it as text.

How context determines the type

The fallback-to-text rule applies only when a literal appears as a standalone SELECT output column. In other contexts, type resolution uses a different source:

Context How the type is resolved
Standalone SELECT output column Falls back to text
One arm of a UNION, INTERSECT, or EXCEPT Taken from the other arm
INSERT ... SELECT Taken from the destination column

In the UNION/INTERSECT/EXCEPT and INSERT ... SELECT cases, the rules described in the preceding sections take precedence, so the fallback rule does not apply.

RETURNING lists follow the same rules as SELECT output lists.