forked from supabase/supautils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_triggers.c
46 lines (37 loc) · 1.5 KB
/
event_triggers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "pg_prelude.h"
#include "event_triggers.h"
// this is the underlying function of `select version();`
extern Datum pgsql_version(PG_FUNCTION_ARGS);
void
force_noop(FmgrInfo *finfo)
{
finfo->fn_addr = (PGFunction) pgsql_version;
finfo->fn_oid = 89; /* this is the oid of pgsql_version function, it's stable and keeps being the same on latest pg version */
finfo->fn_nargs = 0; /* no arguments for version() */
finfo->fn_strict = false;
finfo->fn_retset = false;
finfo->fn_stats = 0; /* no stats collection */
finfo->fn_extra = NULL; /* clear out old context data */
finfo->fn_mcxt = CurrentMemoryContext;
finfo->fn_expr = NULL; /* no parse tree */
}
Oid get_function_owner(func_owner_search search){
// Lookup function name OID. Note that for event trigger functions, there's no arguments.
Oid func_oid = InvalidOid;
switch(search.as){
case FO_SEARCH_NAME:
func_oid = LookupFuncName(search.val.funcname, 0, NULL, false);
break;
case FO_SEARCH_FINFO:
func_oid = search.val.finfo->fn_oid;
break;
}
HeapTuple proc_tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
if (!HeapTupleIsValid(proc_tup))
ereport(ERROR,
(errmsg("cache lookup failed for function %u", func_oid)));
Form_pg_proc procForm = (Form_pg_proc) GETSTRUCT(proc_tup);
Oid func_owner = procForm->proowner;
ReleaseSysCache(proc_tup);
return func_owner;
}