Commit c3086c8f authored by Tom Lane's avatar Tom Lane

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.
parent 6b704bf5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.84 2002/09/18 21:35:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.85 2002/10/24 22:09:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -32,9 +32,6 @@ static Node *coerce_type_typmod(Node *node, ...@@ -32,9 +32,6 @@ static Node *coerce_type_typmod(Node *node,
Oid targetTypeId, int32 targetTypMod, Oid targetTypeId, int32 targetTypMod,
CoercionForm cformat); CoercionForm cformat);
static Oid PreferredType(CATEGORY category, Oid type); static Oid PreferredType(CATEGORY category, Oid type);
static bool find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
CoercionContext ccontext,
Oid *funcid);
static Node *build_func_call(Oid funcid, Oid rettype, List *args, static Node *build_func_call(Oid funcid, Oid rettype, List *args,
CoercionForm fformat); CoercionForm fformat);
...@@ -910,7 +907,7 @@ IsBinaryCoercible(Oid srctype, Oid targettype) ...@@ -910,7 +907,7 @@ IsBinaryCoercible(Oid srctype, Oid targettype)
* to the castfunc value (which may be InvalidOid for a binary-compatible * to the castfunc value (which may be InvalidOid for a binary-compatible
* coercion). * coercion).
*/ */
static bool bool
find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
CoercionContext ccontext, CoercionContext ccontext,
Oid *funcid) Oid *funcid)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.138 2002/10/19 21:23:20 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.139 2002/10/24 22:09:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -770,6 +770,11 @@ func_get_detail(List *funcname, ...@@ -770,6 +770,11 @@ func_get_detail(List *funcname,
* and ones that are coercing a previously-unknown-type literal * and ones that are coercing a previously-unknown-type literal
* constant to a specific type. * constant to a specific type.
* *
* The reason we can restrict our check to binary-compatible
* coercions here is that we expect non-binary-compatible coercions
* to have an implementation function named after the target type.
* That function will be found by normal lookup if appropriate.
*
* NB: it's important that this code stays in sync with what * NB: it's important that this code stays in sync with what
* coerce_type can do, because the caller will try to apply * coerce_type can do, because the caller will try to apply
* coerce_type if we return FUNCDETAIL_COERCION. If we return * coerce_type if we return FUNCDETAIL_COERCION. If we return
...@@ -791,7 +796,9 @@ func_get_detail(List *funcname, ...@@ -791,7 +796,9 @@ func_get_detail(List *funcname,
Node *arg1 = lfirst(fargs); Node *arg1 = lfirst(fargs);
if ((sourceType == UNKNOWNOID && IsA(arg1, Const)) || if ((sourceType == UNKNOWNOID && IsA(arg1, Const)) ||
IsBinaryCoercible(sourceType, targetType)) (find_coercion_pathway(targetType, sourceType,
COERCION_EXPLICIT, funcid) &&
*funcid == InvalidOid))
{ {
/* Yup, it's a type coercion */ /* Yup, it's a type coercion */
*funcid = InvalidOid; *funcid = InvalidOid;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parse_coerce.h,v 1.47 2002/09/18 21:35:24 tgl Exp $ * $Id: parse_coerce.h,v 1.48 2002/10/24 22:09:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -54,6 +54,9 @@ extern Oid select_common_type(List *typeids, const char *context); ...@@ -54,6 +54,9 @@ extern Oid select_common_type(List *typeids, const char *context);
extern Node *coerce_to_common_type(Node *node, Oid targetTypeId, extern Node *coerce_to_common_type(Node *node, Oid targetTypeId,
const char *context); const char *context);
extern bool find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId,
CoercionContext ccontext,
Oid *funcid);
extern Oid find_typmod_coercion_function(Oid typeId, int *nargs); extern Oid find_typmod_coercion_function(Oid typeId, int *nargs);
#endif /* PARSE_COERCE_H */ #endif /* PARSE_COERCE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment