aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_coerce.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-04-09 20:35:55 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-04-09 20:35:55 +0000
commitf2d70d32ebd6c38d4fe93c1a684f5f29e5e76938 (patch)
tree5d041018177cdf6e9ca3ef0cc2eafac580a5bb0b /src/backend/parser/parse_coerce.c
parentc419c224142eb4bbf6e9a47d2d3626f212fda0fc (diff)
downloadpostgresql-f2d70d32ebd6c38d4fe93c1a684f5f29e5e76938.tar.gz
postgresql-f2d70d32ebd6c38d4fe93c1a684f5f29e5e76938.zip
Functions live in namespaces. Qualified function names work, eg
SELECT schema1.func2(...). Aggregate names can be qualified at the syntactic level, but the qualification is ignored for the moment.
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r--src/backend/parser/parse_coerce.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c
index 690a047915a..4dd5777e1e1 100644
--- a/src/backend/parser/parse_coerce.c
+++ b/src/backend/parser/parse_coerce.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.68 2002/03/20 19:44:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.69 2002/04/09 20:35:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -657,7 +657,8 @@ PreferredType(CATEGORY category, Oid type)
* Look for a coercion function between two types.
*
* A coercion function must be named after (the internal name of) its
- * result type, and must accept exactly the specified input type.
+ * result type, and must accept exactly the specified input type. We
+ * also require it to be defined in the same namespace as its result type.
*
* This routine is also used to look for length-coercion functions, which
* are similar but accept a second argument. secondArgType is the type
@@ -669,14 +670,19 @@ PreferredType(CATEGORY category, Oid type)
static Oid
find_coercion_function(Oid targetTypeId, Oid inputTypeId, Oid secondArgType)
{
- char *funcname;
+ Type targetType;
+ char *typname;
+ Oid typnamespace;
Oid oid_array[FUNC_MAX_ARGS];
int nargs;
HeapTuple ftup;
Form_pg_proc pform;
Oid funcid;
- funcname = typeidTypeName(targetTypeId);
+ targetType = typeidType(targetTypeId);
+ typname = NameStr(((Form_pg_type) GETSTRUCT(targetType))->typname);
+ typnamespace = ((Form_pg_type) GETSTRUCT(targetType))->typnamespace;
+
MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid));
oid_array[0] = inputTypeId;
if (OidIsValid(secondArgType))
@@ -687,22 +693,27 @@ find_coercion_function(Oid targetTypeId, Oid inputTypeId, Oid secondArgType)
else
nargs = 1;
- ftup = SearchSysCache(PROCNAME,
- PointerGetDatum(funcname),
- Int32GetDatum(nargs),
+ ftup = SearchSysCache(PROCNAMENSP,
+ CStringGetDatum(typname),
+ Int16GetDatum(nargs),
PointerGetDatum(oid_array),
- 0);
+ ObjectIdGetDatum(typnamespace));
if (!HeapTupleIsValid(ftup))
+ {
+ ReleaseSysCache(targetType);
return InvalidOid;
+ }
/* Make sure the function's result type is as expected, too */
pform = (Form_pg_proc) GETSTRUCT(ftup);
if (pform->prorettype != targetTypeId)
{
ReleaseSysCache(ftup);
+ ReleaseSysCache(targetType);
return InvalidOid;
}
funcid = ftup->t_data->t_oid;
ReleaseSysCache(ftup);
+ ReleaseSysCache(targetType);
return funcid;
}