Skip to content

Commit f758097

Browse files
committed
Reorder tests in parse_coerce so that ANY/ANYELEMENT/ANYARRAY coercion
does not affect UNKNOWN-type literals or Params. This fixes the recent complaint about count('x') being broken, and improves consistency in a few other respects too.
1 parent b40b330 commit f758097

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/backend/parser/parse_coerce.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.112 2003/11/29 19:51:52 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.113 2003/12/17 19:49:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -153,6 +153,14 @@ coerce_type(ParseState *pstate, Node *node,
153153
/* no conversion needed */
154154
return node;
155155
}
156+
if (targetTypeId == ANYOID ||
157+
targetTypeId == ANYARRAYOID ||
158+
targetTypeId == ANYELEMENTOID)
159+
{
160+
/* assume can_coerce_type verified that implicit coercion is okay */
161+
/* NB: we do NOT want a RelabelType here */
162+
return node;
163+
}
156164
if (inputTypeId == UNKNOWNOID && IsA(node, Const))
157165
{
158166
/*
@@ -260,14 +268,6 @@ coerce_type(ParseState *pstate, Node *node,
260268
param->paramtype = targetTypeId;
261269
return (Node *) param;
262270
}
263-
if (targetTypeId == ANYOID ||
264-
targetTypeId == ANYARRAYOID ||
265-
targetTypeId == ANYELEMENTOID)
266-
{
267-
/* assume can_coerce_type verified that implicit coercion is okay */
268-
/* NB: we do NOT want a RelabelType here */
269-
return node;
270-
}
271271
if (find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
272272
&funcId))
273273
{
@@ -372,17 +372,6 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
372372
if (!typeidIsValid(targetTypeId))
373373
return false;
374374

375-
/*
376-
* If input is an untyped string constant, assume we can convert
377-
* it to anything except a class type.
378-
*/
379-
if (inputTypeId == UNKNOWNOID)
380-
{
381-
if (ISCOMPLEX(targetTypeId))
382-
return false;
383-
continue;
384-
}
385-
386375
/* accept if target is ANY */
387376
if (targetTypeId == ANYOID)
388377
continue;
@@ -395,6 +384,17 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
395384
continue;
396385
}
397386

387+
/*
388+
* If input is an untyped string constant, assume we can convert
389+
* it to anything except a class type.
390+
*/
391+
if (inputTypeId == UNKNOWNOID)
392+
{
393+
if (ISCOMPLEX(targetTypeId))
394+
return false;
395+
continue;
396+
}
397+
398398
/*
399399
* If pg_cast shows that we can coerce, accept. This test now
400400
* covers both binary-compatible and coercion-function cases.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy