Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit356f85f

Browse files
committed
Doc: add example of type resolution in nested UNIONs.
Section 10.5 didn't say explicitly that multiple UNIONs are resolvedpairwise. Since the resolution algorithm is described as taking anynumber of inputs, readers might well think that a query like"select x union select y union select z" would be resolved byconsidering x, y, and z in one resolution step. But that's not whathappens (and I think that behavior is per SQL spec). Add an exampleclarifying this point.Per bug #15129 from Philippe Beaudoin.Discussion:https://postgr.es/m/152196085023.32649.9916472370480121694@wrigleys.postgresql.org
1 parent7b55a3b commit356f85f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎doc/src/sgml/typeconv.sgml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,5 +1077,34 @@ result type is resolved as <type>real</>.
10771077
</para>
10781078
</example>
10791079

1080+
<example>
1081+
<title>Type Resolution in a Nested Union</title>
1082+
1083+
<para>
1084+
<screen>
1085+
SELECT NULL UNION SELECT NULL UNION SELECT 1;
1086+
1087+
ERROR: UNION types text and integer cannot be matched
1088+
</screen>
1089+
This failure occurs because <productname>PostgreSQL</productname> treats
1090+
multiple <literal>UNION</literal>s as a nest of pairwise operations;
1091+
that is, this input is the same as
1092+
<screen>
1093+
(SELECT NULL UNION SELECT NULL) UNION SELECT 1;
1094+
</screen>
1095+
The inner <literal>UNION</literal> is resolved as emitting
1096+
type <type>text</type>, according to the rules given above. Then the
1097+
outer <literal>UNION</literal> has inputs of types <type>text</type>
1098+
and <type>integer</type>, leading to the observed error. The problem
1099+
can be fixed by ensuring that the leftmost <literal>UNION</literal>
1100+
has at least one input of the desired result type.
1101+
</para>
1102+
1103+
<para>
1104+
<literal>INTERSECT</literal> and <literal>EXCEPT</literal> operations are
1105+
likewise resolved pairwise. However, the other constructs described in this
1106+
section consider all of their inputs in one resolution step.
1107+
</para>
1108+
</example>
10801109
</sect1>
10811110
</chapter>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp