Skip to content

Commit c3086c8

Browse files
committed
Function-call-style type coercions should be treated as explicit
coercions, not implicit ones. For example, 'select abstime(1035497293)' should succeed because there is an explicit binary coercion from int4 to abstime.
1 parent 6b704bf commit c3086c8

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/backend/parser/parse_coerce.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.84 2002/09/18 21:35:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.85 2002/10/24 22:09:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -32,9 +32,6 @@ static Node *coerce_type_typmod(Node *node,
3232
Oid targetTypeId, int32 targetTypMod,
3333
CoercionForm cformat);
3434
static Oid PreferredType(CATEGORY category, Oid type);
35-
static bool find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
36-
CoercionContext ccontext,
37-
Oid *funcid);
3835
static Node *build_func_call(Oid funcid, Oid rettype, List *args,
3936
CoercionForm fformat);
4037

@@ -910,7 +907,7 @@ IsBinaryCoercible(Oid srctype, Oid targettype)
910907
* to the castfunc value (which may be InvalidOid for a binary-compatible
911908
* coercion).
912909
*/
913-
static bool
910+
bool
914911
find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
915912
CoercionContext ccontext,
916913
Oid *funcid)

src/backend/parser/parse_func.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.138 2002/10/19 21:23:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.139 2002/10/24 22:09:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -770,6 +770,11 @@ func_get_detail(List *funcname,
770770
* and ones that are coercing a previously-unknown-type literal
771771
* constant to a specific type.
772772
*
773+
* The reason we can restrict our check to binary-compatible
774+
* coercions here is that we expect non-binary-compatible coercions
775+
* to have an implementation function named after the target type.
776+
* That function will be found by normal lookup if appropriate.
777+
*
773778
* NB: it's important that this code stays in sync with what
774779
* coerce_type can do, because the caller will try to apply
775780
* coerce_type if we return FUNCDETAIL_COERCION. If we return
@@ -791,7 +796,9 @@ func_get_detail(List *funcname,
791796
Node *arg1 = lfirst(fargs);
792797

793798
if ((sourceType == UNKNOWNOID && IsA(arg1, Const)) ||
794-
IsBinaryCoercible(sourceType, targetType))
799+
(find_coercion_pathway(targetType, sourceType,
800+
COERCION_EXPLICIT, funcid) &&
801+
*funcid == InvalidOid))
795802
{
796803
/* Yup, it's a type coercion */
797804
*funcid = InvalidOid;

src/include/parser/parse_coerce.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parse_coerce.h,v 1.47 2002/09/18 21:35:24 tgl Exp $
10+
* $Id: parse_coerce.h,v 1.48 2002/10/24 22:09:00 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -54,6 +54,9 @@ extern Oid select_common_type(List *typeids, const char *context);
5454
extern Node *coerce_to_common_type(Node *node, Oid targetTypeId,
5555
const char *context);
5656

57+
extern bool find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
58+
CoercionContext ccontext,
59+
Oid *funcid);
5760
extern Oid find_typmod_coercion_function(Oid typeId, int *nargs);
5861

5962
#endif /* PARSE_COERCE_H */

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