- /* guardian value */
-#ifndef WIN32
- { MAXINT, 0, (func_ptr) NULL }
-#else
- { INT_MAX, 0, (func_ptr) NULL }
-#endif /* WIN32 */
+ /* dummy entry is easier than getting rid of comma after last real one */
+ { 0, 0, (func_ptr) NULL, NULL }
};
-/* Note FMGR_NBUILTINS excludes the guardian entry, which is probably
- * not really needed at all ...
- */
+/* Note FMGR_NBUILTINS excludes the dummy entry */
#define FMGR_NBUILTINS ((sizeof(fmgr_builtins) / sizeof(FmgrCall)) - 1)
FmgrCall *fmgr_isbuiltin(Oid id)
return (FmgrCall *) NULL;
}
+func_ptr fmgr_lookupByName(char *name)
+{
+ /* Lookup a builtin by name. Note there can be more than one entry in
+ * the array matching this name, but they should all point to the same
+ * routine.
+ */
+ int i;
+ for (i=0; i
+ if (strcmp(name, fmgr_builtins[i].funcName) == 0)
+ return fmgr_builtins[i].func;
+ }
+ return (func_ptr) NULL;
+}
+
FuNkYfMgRtAbStUfF
rm -f $RAWFILE
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.24 1999/04/03 22:57:29 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.25 1999/04/09 22:35:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
#include "nodes/params.h"
+#include "utils/builtins.h"
#include "utils/elog.h"
#include "nodes/parsenodes.h"
HeapTuple languageTuple;
Form_pg_language languageStruct;
Oid language;
+ char *prosrc;
finfo->fn_addr = NULL;
finfo->fn_plhandler = NULL;
{
case INTERNALlanguageId:
/*
- * Since we already tried to look up the OID as a builtin
- * function, we should never get here...
+ * For an ordinary builtin function, we should never get here
+ * because the isbuiltin() search above will have succeeded.
+ * However, if the user has done a CREATE FUNCTION to create
+ * an alias for a builtin function, we end up here. In that
+ * case we have to look up the function by name. The name
+ * of the internal function is stored in prosrc (it doesn't
+ * have to be the same as the name of the alias!)
*/
- elog(ERROR, "fmgr_info: function %d: not in internal table",
- procedureId);
+ prosrc = textout(&(procedureStruct->prosrc));
+ finfo->fn_addr = fmgr_lookupByName(prosrc);
+ if (!finfo->fn_addr)
+ elog(ERROR, "fmgr_info: function %s not in internal table",
+ prosrc);
+ finfo->fn_nargs = procedureStruct->pronargs;
+ pfree(prosrc);
break;
case ClanguageId:
finfo->fn_addr = fmgr_dynamic(procedureId, &(finfo->fn_nargs));
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: fmgrtab.h,v 1.10 1999/03/29 01:30:41 tgl Exp $
+ * $Id: fmgrtab.h,v 1.11 1999/04/09 22:35:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Oid proid;
int nargs;
func_ptr func;
- int dummy; /* pad struct to 4 words for fast indexing */
+ char *funcName;
} FmgrCall;
extern FmgrCall *fmgr_isbuiltin(Oid id);
-
+extern func_ptr fmgr_lookupByName(char *name);
extern void load_file(char *filename);
#endif /* FMGRTAB_H */