* pg_proc.c
* routines to support manipulation of the pg_proc relation
*
- * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.174 2010/04/05 01:09:52 tgl Exp $
+ * src/backend/catalog/pg_proc.c
*
*-------------------------------------------------------------------------
*/
#include "access/xact.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
+#include "catalog/objectaccess.h"
#include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h"
values[Anum_pg_proc_procost - 1] = Float4GetDatum(procost);
values[Anum_pg_proc_prorows - 1] = Float4GetDatum(prorows);
values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType);
+ values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(InvalidOid);
values[Anum_pg_proc_proisagg - 1] = BoolGetDatum(isAgg);
values[Anum_pg_proc_proiswindow - 1] = BoolGetDatum(isWindowFunc);
values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer);
* Create dependencies for the new function. If we are updating an
* existing function, first delete any existing pg_depend entries.
* (However, since we are not changing ownership or permissions, the
- * shared dependencies do *not* need to change, and we leave them alone.)
+ * shared dependencies do *not* need to change, and we leave them alone.
+ * We also don't change any pre-existing extension-membership dependency.)
*/
if (is_update)
- deleteDependencyRecordsFor(ProcedureRelationId, retval);
+ deleteDependencyRecordsFor(ProcedureRelationId, retval, true);
myself.classId = ProcedureRelationId;
myself.objectId = retval;
nnewmembers, newmembers);
}
+ /* dependency on extension */
+ if (!is_update)
+ recordDependencyOnCurrentExtension(&myself);
+
heap_freetuple(tup);
+ /* Post creation hook for new function */
+ InvokeObjectAccessHook(OAT_POST_CREATE, ProcedureRelationId, retval, 0);
+
heap_close(rel, RowExclusiveLock);
/* Verify function body */
if (OidIsValid(languageValidator))
{
+ ArrayType *set_items;
+ int save_nestlevel;
+
/* Advance command counter so new tuple can be seen by validator */
CommandCounterIncrement();
+
+ /* Set per-function configuration parameters */
+ set_items = (ArrayType *) DatumGetPointer(proconfig);
+ if (set_items) /* Need a new GUC nesting level */
+ {
+ save_nestlevel = NewGUCNestLevel();
+ ProcessGUCArray(set_items,
+ (superuser() ? PGC_SUSET : PGC_USERSET),
+ PGC_S_SESSION,
+ GUC_ACTION_SAVE);
+ }
+ else
+ save_nestlevel = 0; /* keep compiler quiet */
+
OidFunctionCall1(languageValidator, ObjectIdGetDatum(retval));
+
+ if (set_items)
+ AtEOXact_GUC(true, save_nestlevel);
}
return retval;
{
Oid funcoid = PG_GETARG_OID(0);
HeapTuple tuple;
- Form_pg_proc proc;
bool isnull;
Datum tmp;
char *prosrc;
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for function %u", funcoid);
- proc = (Form_pg_proc) GETSTRUCT(tuple);
tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
if (isnull)
Oid funcoid = PG_GETARG_OID(0);
void *libraryhandle;
HeapTuple tuple;
- Form_pg_proc proc;
bool isnull;
Datum tmp;
char *prosrc;
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid));
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for function %u", funcoid);
- proc = (Form_pg_proc) GETSTRUCT(tuple);
tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
if (isnull)
Oid funcoid = PG_GETARG_OID(0);
HeapTuple tuple;
Form_pg_proc proc;
+ List *raw_parsetree_list;
List *querytree_list;
+ ListCell *lc;
bool isnull;
Datum tmp;
char *prosrc;
* We can run the text through the raw parser though; this will at
* least catch silly syntactic errors.
*/
+ raw_parsetree_list = pg_parse_query(prosrc);
+
if (!haspolyarg)
{
- querytree_list = pg_parse_and_rewrite(prosrc,
- proc->proargtypes.values,
- proc->pronargs);
+ /*
+ * OK to do full precheck: analyze and rewrite the queries, then
+ * verify the result type.
+ */
+ SQLFunctionParseInfoPtr pinfo;
+
+ /* But first, set up parameter information */
+ pinfo = prepare_sql_fn_parse_info(tuple, NULL, InvalidOid);
+
+ querytree_list = NIL;
+ foreach(lc, raw_parsetree_list)
+ {
+ Node *parsetree = (Node *) lfirst(lc);
+ List *querytree_sublist;
+
+ querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
+ prosrc,
+ (ParserSetupHook) sql_fn_parser_setup,
+ pinfo);
+ querytree_list = list_concat(querytree_list,
+ querytree_sublist);
+ }
+
(void) check_sql_fn_retval(funcoid, proc->prorettype,
querytree_list,
NULL, NULL);
}
- else
- querytree_list = pg_parse_query(prosrc);
error_context_stack = sqlerrcontext.previous;
}