@@ -94,6 +94,7 @@ static Oid findTypeSendFunction(List *procname, Oid typeOid);
9494static Oid findTypeTypmodinFunction (List * procname );
9595static Oid findTypeTypmodoutFunction (List * procname );
9696static Oid findTypeAnalyzeFunction (List * procname , Oid typeOid );
97+ static Oid findTypeSubscriptionFunction (List * procname , Oid typeOid );
9798static Oid findRangeSubOpclass (List * opcname , Oid subtype );
9899static Oid findRangeCanonicalFunction (List * procname , Oid typeOid );
99100static Oid findRangeSubtypeDiffFunction (List * procname , Oid subtype );
@@ -520,7 +521,7 @@ DefineType(List *names, List *parameters)
520521 analyzeOid = findTypeAnalyzeFunction (analyzeName , typoid );
521522
522523 if (subscriptionName )
523- subscriptionOid = findTypeAnalyzeFunction (subscriptionName , typoid );
524+ subscriptionOid = findTypeSubscriptionFunction (subscriptionName , typoid );
524525
525526 /*
526527 * Check permissions on functions. We choose to require the creator/owner
@@ -1916,6 +1917,33 @@ findTypeAnalyzeFunction(List *procname, Oid typeOid)
19161917 return procOid ;
19171918}
19181919
1920+ static Oid
1921+ findTypeSubscriptionFunction (List * procname , Oid typeOid )
1922+ {
1923+ Oid argList [1 ];
1924+ Oid procOid ;
1925+
1926+ /*
1927+ * Analyze functions always take one INTERNAL argument and return INTERNAL.
1928+ */
1929+ argList [0 ] = INTERNALOID ;
1930+
1931+ procOid = LookupFuncName (procname , 1 , argList , true);
1932+ if (!OidIsValid (procOid ))
1933+ ereport (ERROR ,
1934+ (errcode (ERRCODE_UNDEFINED_FUNCTION ),
1935+ errmsg ("function %s does not exist" ,
1936+ func_signature_string (procname , 1 , NIL , argList ))));
1937+
1938+ if (get_func_rettype (procOid ) != INTERNALOID )
1939+ ereport (ERROR ,
1940+ (errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
1941+ errmsg ("type subscription function %s must return type %s" ,
1942+ NameListToString (procname ), "internal" )));
1943+
1944+ return procOid ;
1945+ }
1946+
19191947/*
19201948 * Find suitable support functions and opclasses for a range type.
19211949 */
0 commit comments