1 /*-------------------------------------------------------------------------
4 * code to support accessing and searching namespaces
6 * This is separate from pg_namespace.c, which contains the routines that
7 * directly manipulate the pg_namespace system catalog. This module
8 * provides routines associated with defining a "namespace search path"
9 * and implementing search-path-controlled searches.
12 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
16 * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.67 2004/06/18 06:13:19 tgl Exp $
18 *-------------------------------------------------------------------------
22 #include "access/xact.h"
23 #include "catalog/catname.h"
24 #include "catalog/dependency.h"
25 #include "catalog/namespace.h"
26 #include "catalog/pg_conversion.h"
27 #include "catalog/pg_namespace.h"
28 #include "catalog/pg_opclass.h"
29 #include "catalog/pg_operator.h"
30 #include "catalog/pg_proc.h"
31 #include "catalog/pg_shadow.h"
32 #include "catalog/pg_type.h"
33 #include "commands/dbcommands.h"
34 #include "lib/stringinfo.h"
35 #include "miscadmin.h"
36 #include "nodes/makefuncs.h"
37 #include "storage/backendid.h"
38 #include "storage/ipc.h"
39 #include "utils/acl.h"
40 #include "utils/builtins.h"
41 #include "utils/catcache.h"
42 #include "utils/guc.h"
43 #include "utils/inval.h"
44 #include "utils/lsyscache.h"
45 #include "utils/memutils.h"
46 #include "utils/syscache.h"
50 * The namespace search path is a possibly-empty list of namespace OIDs.
51 * In addition to the explicit list, several implicitly-searched namespaces
54 * 1. If a "special" namespace has been set by PushSpecialNamespace, it is
55 * always searched first. (This is a hack for CREATE SCHEMA.)
57 * 2. If a TEMP table namespace has been initialized in this session, it
58 * is always searched just after any special namespace.
60 * 3. The system catalog namespace is always searched. If the system
61 * namespace is present in the explicit path then it will be searched in
62 * the specified order; otherwise it will be searched after TEMP tables and
63 * *before* the explicit list. (It might seem that the system namespace
64 * should be implicitly last, but this behavior appears to be required by
65 * SQL99. Also, this provides a way to search the system namespace first
66 * without thereby making it the default creation target namespace.)
68 * The default creation target namespace is normally equal to the first
69 * element of the explicit list, but is the "special" namespace when one
70 * has been set. If the explicit list is empty and there is no special
71 * namespace, there is no default target.
73 * In bootstrap mode, the search path is set equal to 'pg_catalog', so that
74 * the system namespace is the only one searched or inserted into.
75 * The initdb script is also careful to set search_path to 'pg_catalog' for
76 * its post-bootstrap standalone backend runs. Otherwise the default search
77 * path is determined by GUC. The factory default path contains the PUBLIC
78 * namespace (if it exists), preceded by the user's personal namespace
81 * If namespaceSearchPathValid is false, then namespaceSearchPath (and other
82 * derived variables) need to be recomputed from namespace_search_path.
83 * We mark it invalid upon an assignment to namespace_search_path or receipt
84 * of a syscache invalidation event for pg_namespace. The recomputation
85 * is done during the next lookup attempt.
87 * Any namespaces mentioned in namespace_search_path that are not readable
88 * by the current user ID are simply left out of namespaceSearchPath; so
89 * we have to be willing to recompute the path when current userid changes.
90 * namespaceUser is the userid the path has been computed for.
93 static List *namespaceSearchPath = NIL;
95 static Oid namespaceUser = InvalidOid;
97 /* default place to create stuff; if InvalidOid, no default */
98 static Oid defaultCreationNamespace = InvalidOid;
100 /* first explicit member of list; usually same as defaultCreationNamespace */
101 static Oid firstExplicitNamespace = InvalidOid;
103 /* The above four values are valid only if namespaceSearchPathValid */
104 static bool namespaceSearchPathValid = true;
107 * myTempNamespace is InvalidOid until and unless a TEMP namespace is set up
108 * in a particular backend session (this happens when a CREATE TEMP TABLE
109 * command is first executed). Thereafter it's the OID of the temp namespace.
110 * firstTempTransaction flags whether we've committed creation of the TEMP
113 static Oid myTempNamespace = InvalidOid;
115 static bool firstTempTransaction = false;
118 * "Special" namespace for CREATE SCHEMA. If set, it's the first search
119 * path element, and also the default creation namespace.
121 static Oid mySpecialNamespace = InvalidOid;
124 * This is the text equivalent of the search path --- it's the value
125 * of the GUC variable 'search_path'.
127 char *namespace_search_path = NULL;
130 /* Local functions */
131 static void recomputeNamespacePath(void);
132 static void InitTempTableNamespace(void);
133 static void RemoveTempRelations(Oid tempNamespaceId);
134 static void RemoveTempRelationsCallback(int code, Datum arg);
135 static void NamespaceCallback(Datum arg, Oid relid);
137 /* These don't really need to appear in any header file */
138 Datum pg_table_is_visible(PG_FUNCTION_ARGS);
139 Datum pg_type_is_visible(PG_FUNCTION_ARGS);
140 Datum pg_function_is_visible(PG_FUNCTION_ARGS);
141 Datum pg_operator_is_visible(PG_FUNCTION_ARGS);
142 Datum pg_opclass_is_visible(PG_FUNCTION_ARGS);
143 Datum pg_conversion_is_visible(PG_FUNCTION_ARGS);
148 * Given a RangeVar describing an existing relation,
149 * select the proper namespace and look up the relation OID.
151 * If the relation is not found, return InvalidOid if failOK = true,
152 * otherwise raise an error.
155 RangeVarGetRelid(const RangeVar *relation, bool failOK)
161 * We check the catalog name and then ignore it.
163 if (relation->catalogname)
165 if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0)
167 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
168 errmsg("cross-database references are not implemented: \"%s.%s.%s\"",
169 relation->catalogname, relation->schemaname,
170 relation->relname)));
173 if (relation->schemaname)
175 /* use exact schema given */
176 namespaceId = LookupExplicitNamespace(relation->schemaname);
177 relId = get_relname_relid(relation->relname, namespaceId);
181 /* search the namespace path */
182 relId = RelnameGetRelid(relation->relname);
185 if (!OidIsValid(relId) && !failOK)
187 if (relation->schemaname)
189 (errcode(ERRCODE_UNDEFINED_TABLE),
190 errmsg("relation \"%s.%s\" does not exist",
191 relation->schemaname, relation->relname)));
194 (errcode(ERRCODE_UNDEFINED_TABLE),
195 errmsg("relation \"%s\" does not exist",
196 relation->relname)));
202 * RangeVarGetCreationNamespace
203 * Given a RangeVar describing a to-be-created relation,
204 * choose which namespace to create it in.
206 * Note: calling this may result in a CommandCounterIncrement operation.
207 * That will happen on the first request for a temp table in any particular
208 * backend run; we will need to either create or clean out the temp schema.
211 RangeVarGetCreationNamespace(const RangeVar *newRelation)
216 * We check the catalog name and then ignore it.
218 if (newRelation->catalogname)
220 if (strcmp(newRelation->catalogname, get_database_name(MyDatabaseId)) != 0)
222 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
223 errmsg("cross-database references are not implemented: \"%s.%s.%s\"",
224 newRelation->catalogname, newRelation->schemaname,
225 newRelation->relname)));
228 if (newRelation->istemp)
230 /* TEMP tables are created in our backend-local temp namespace */
231 if (newRelation->schemaname)
233 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
234 errmsg("temporary tables may not specify a schema name")));
235 /* Initialize temp namespace if first time through */
236 if (!OidIsValid(myTempNamespace))
237 InitTempTableNamespace();
238 return myTempNamespace;
241 if (newRelation->schemaname)
243 /* use exact schema given */
244 namespaceId = GetSysCacheOid(NAMESPACENAME,
245 CStringGetDatum(newRelation->schemaname),
247 if (!OidIsValid(namespaceId))
249 (errcode(ERRCODE_UNDEFINED_SCHEMA),
250 errmsg("schema \"%s\" does not exist",
251 newRelation->schemaname)));
252 /* we do not check for USAGE rights here! */
256 /* use the default creation namespace */
257 recomputeNamespacePath();
258 namespaceId = defaultCreationNamespace;
259 if (!OidIsValid(namespaceId))
261 (errcode(ERRCODE_UNDEFINED_SCHEMA),
262 errmsg("no schema has been selected to create in")));
265 /* Note: callers will check for CREATE rights when appropriate */
272 * Try to resolve an unqualified relation name.
273 * Returns OID if relation found in search path, else InvalidOid.
276 RelnameGetRelid(const char *relname)
281 recomputeNamespacePath();
283 foreach(l, namespaceSearchPath)
285 Oid namespaceId = lfirst_oid(l);
287 relid = get_relname_relid(relname, namespaceId);
288 if (OidIsValid(relid))
292 /* Not found in path */
299 * Determine whether a relation (identified by OID) is visible in the
300 * current search path. Visible means "would be found by searching
301 * for the unqualified relation name".
304 RelationIsVisible(Oid relid)
307 Form_pg_class relform;
311 reltup = SearchSysCache(RELOID,
312 ObjectIdGetDatum(relid),
314 if (!HeapTupleIsValid(reltup))
315 elog(ERROR, "cache lookup failed for relation %u", relid);
316 relform = (Form_pg_class) GETSTRUCT(reltup);
318 recomputeNamespacePath();
321 * Quick check: if it ain't in the path at all, it ain't visible.
322 * Items in the system namespace are surely in the path and so we
323 * needn't even do list_member_oid() for them.
325 relnamespace = relform->relnamespace;
326 if (relnamespace != PG_CATALOG_NAMESPACE &&
327 !list_member_oid(namespaceSearchPath, relnamespace))
332 * If it is in the path, it might still not be visible; it could
333 * be hidden by another relation of the same name earlier in the
334 * path. So we must do a slow check to see if this rel would be
335 * found by RelnameGetRelid.
337 char *relname = NameStr(relform->relname);
339 visible = (RelnameGetRelid(relname) == relid);
342 ReleaseSysCache(reltup);
350 * Try to resolve an unqualified datatype name.
351 * Returns OID if type found in search path, else InvalidOid.
353 * This is essentially the same as RelnameGetRelid.
356 TypenameGetTypid(const char *typname)
361 recomputeNamespacePath();
363 foreach(l, namespaceSearchPath)
365 Oid namespaceId = lfirst_oid(l);
367 typid = GetSysCacheOid(TYPENAMENSP,
368 PointerGetDatum(typname),
369 ObjectIdGetDatum(namespaceId),
371 if (OidIsValid(typid))
375 /* Not found in path */
381 * Determine whether a type (identified by OID) is visible in the
382 * current search path. Visible means "would be found by searching
383 * for the unqualified type name".
386 TypeIsVisible(Oid typid)
389 Form_pg_type typform;
393 typtup = SearchSysCache(TYPEOID,
394 ObjectIdGetDatum(typid),
396 if (!HeapTupleIsValid(typtup))
397 elog(ERROR, "cache lookup failed for type %u", typid);
398 typform = (Form_pg_type) GETSTRUCT(typtup);
400 recomputeNamespacePath();
403 * Quick check: if it ain't in the path at all, it ain't visible.
404 * Items in the system namespace are surely in the path and so we
405 * needn't even do list_member_oid() for them.
407 typnamespace = typform->typnamespace;
408 if (typnamespace != PG_CATALOG_NAMESPACE &&
409 !list_member_oid(namespaceSearchPath, typnamespace))
414 * If it is in the path, it might still not be visible; it could
415 * be hidden by another type of the same name earlier in the path.
416 * So we must do a slow check to see if this type would be found
417 * by TypenameGetTypid.
419 char *typname = NameStr(typform->typname);
421 visible = (TypenameGetTypid(typname) == typid);
424 ReleaseSysCache(typtup);
431 * FuncnameGetCandidates
432 * Given a possibly-qualified function name and argument count,
433 * retrieve a list of the possible matches.
435 * If nargs is -1, we return all functions matching the given name,
436 * regardless of argument count.
438 * We search a single namespace if the function name is qualified, else
439 * all namespaces in the search path. The return list will never contain
440 * multiple entries with identical argument lists --- in the multiple-
441 * namespace case, we arrange for entries in earlier namespaces to mask
442 * identical entries in later namespaces.
445 FuncnameGetCandidates(List *names, int nargs)
447 FuncCandidateList resultList = NULL;
454 /* deconstruct the name list */
455 DeconstructQualifiedName(names, &schemaname, &funcname);
459 /* use exact schema given */
460 namespaceId = LookupExplicitNamespace(schemaname);
464 /* flag to indicate we need namespace search */
465 namespaceId = InvalidOid;
466 recomputeNamespacePath();
469 /* Search syscache by name and (optionally) nargs only */
471 catlist = SearchSysCacheList(PROCNAMENSP, 2,
472 CStringGetDatum(funcname),
473 Int16GetDatum(nargs),
476 catlist = SearchSysCacheList(PROCNAMENSP, 1,
477 CStringGetDatum(funcname),
480 for (i = 0; i < catlist->n_members; i++)
482 HeapTuple proctup = &catlist->members[i]->tuple;
483 Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
485 FuncCandidateList newResult;
487 nargs = procform->pronargs;
489 if (OidIsValid(namespaceId))
491 /* Consider only procs in specified namespace */
492 if (procform->pronamespace != namespaceId)
494 /* No need to check args, they must all be different */
498 /* Consider only procs that are in the search path */
501 foreach(nsp, namespaceSearchPath)
503 if (procform->pronamespace == lfirst_oid(nsp))
508 continue; /* proc is not in search path */
511 * Okay, it's in the search path, but does it have the same
512 * arguments as something we already accepted? If so, keep
513 * only the one that appears earlier in the search path.
515 * If we have an ordered list from SearchSysCacheList (the normal
516 * case), then any conflicting proc must immediately adjoin
517 * this one in the list, so we only need to look at the newest
518 * result item. If we have an unordered list, we have to scan
519 * the whole result list.
523 FuncCandidateList prevResult;
525 if (catlist->ordered)
527 if (nargs == resultList->nargs &&
528 memcmp(procform->proargtypes, resultList->args,
529 nargs * sizeof(Oid)) == 0)
530 prevResult = resultList;
536 for (prevResult = resultList;
538 prevResult = prevResult->next)
540 if (nargs == prevResult->nargs &&
541 memcmp(procform->proargtypes, prevResult->args,
542 nargs * sizeof(Oid)) == 0)
548 /* We have a match with a previous result */
549 Assert(pathpos != prevResult->pathpos);
550 if (pathpos > prevResult->pathpos)
551 continue; /* keep previous result */
552 /* replace previous result */
553 prevResult->pathpos = pathpos;
554 prevResult->oid = HeapTupleGetOid(proctup);
555 continue; /* args are same, of course */
561 * Okay to add it to result list
563 newResult = (FuncCandidateList)
564 palloc(sizeof(struct _FuncCandidateList) - sizeof(Oid)
565 + nargs * sizeof(Oid));
566 newResult->pathpos = pathpos;
567 newResult->oid = HeapTupleGetOid(proctup);
568 newResult->nargs = nargs;
569 memcpy(newResult->args, procform->proargtypes, nargs * sizeof(Oid));
571 newResult->next = resultList;
572 resultList = newResult;
575 ReleaseSysCacheList(catlist);
582 * Determine whether a function (identified by OID) is visible in the
583 * current search path. Visible means "would be found by searching
584 * for the unqualified function name with exact argument matches".
587 FunctionIsVisible(Oid funcid)
590 Form_pg_proc procform;
594 proctup = SearchSysCache(PROCOID,
595 ObjectIdGetDatum(funcid),
597 if (!HeapTupleIsValid(proctup))
598 elog(ERROR, "cache lookup failed for function %u", funcid);
599 procform = (Form_pg_proc) GETSTRUCT(proctup);
601 recomputeNamespacePath();
604 * Quick check: if it ain't in the path at all, it ain't visible.
605 * Items in the system namespace are surely in the path and so we
606 * needn't even do list_member_oid() for them.
608 pronamespace = procform->pronamespace;
609 if (pronamespace != PG_CATALOG_NAMESPACE &&
610 !list_member_oid(namespaceSearchPath, pronamespace))
615 * If it is in the path, it might still not be visible; it could
616 * be hidden by another proc of the same name and arguments
617 * earlier in the path. So we must do a slow check to see if this
618 * is the same proc that would be found by FuncnameGetCandidates.
620 char *proname = NameStr(procform->proname);
621 int nargs = procform->pronargs;
622 FuncCandidateList clist;
626 clist = FuncnameGetCandidates(list_make1(makeString(proname)), nargs);
628 for (; clist; clist = clist->next)
630 if (memcmp(clist->args, procform->proargtypes,
631 nargs * sizeof(Oid)) == 0)
633 /* Found the expected entry; is it the right proc? */
634 visible = (clist->oid == funcid);
640 ReleaseSysCache(proctup);
647 * OpernameGetCandidates
648 * Given a possibly-qualified operator name and operator kind,
649 * retrieve a list of the possible matches.
651 * If oprkind is '\0', we return all operators matching the given name,
652 * regardless of arguments.
654 * We search a single namespace if the operator name is qualified, else
655 * all namespaces in the search path. The return list will never contain
656 * multiple entries with identical argument lists --- in the multiple-
657 * namespace case, we arrange for entries in earlier namespaces to mask
658 * identical entries in later namespaces.
660 * The returned items always have two args[] entries --- one or the other
661 * will be InvalidOid for a prefix or postfix oprkind. nargs is 2, too.
664 OpernameGetCandidates(List *names, char oprkind)
666 FuncCandidateList resultList = NULL;
667 char *resultSpace = NULL;
675 /* deconstruct the name list */
676 DeconstructQualifiedName(names, &schemaname, &opername);
680 /* use exact schema given */
681 namespaceId = LookupExplicitNamespace(schemaname);
685 /* flag to indicate we need namespace search */
686 namespaceId = InvalidOid;
687 recomputeNamespacePath();
690 /* Search syscache by name only */
691 catlist = SearchSysCacheList(OPERNAMENSP, 1,
692 CStringGetDatum(opername),
696 * In typical scenarios, most if not all of the operators found by the
697 * catcache search will end up getting returned; and there can be quite
698 * a few, for common operator names such as '=' or '+'. To reduce the
699 * time spent in palloc, we allocate the result space as an array large
700 * enough to hold all the operators. The original coding of this routine
701 * did a separate palloc for each operator, but profiling revealed that
702 * the pallocs used an unreasonably large fraction of parsing time.
704 #define SPACE_PER_OP MAXALIGN(sizeof(struct _FuncCandidateList) + sizeof(Oid))
706 if (catlist->n_members > 0)
707 resultSpace = palloc(catlist->n_members * SPACE_PER_OP);
709 for (i = 0; i < catlist->n_members; i++)
711 HeapTuple opertup = &catlist->members[i]->tuple;
712 Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
714 FuncCandidateList newResult;
716 /* Ignore operators of wrong kind, if specific kind requested */
717 if (oprkind && operform->oprkind != oprkind)
720 if (OidIsValid(namespaceId))
722 /* Consider only opers in specified namespace */
723 if (operform->oprnamespace != namespaceId)
725 /* No need to check args, they must all be different */
729 /* Consider only opers that are in the search path */
732 foreach(nsp, namespaceSearchPath)
734 if (operform->oprnamespace == lfirst_oid(nsp))
739 continue; /* oper is not in search path */
742 * Okay, it's in the search path, but does it have the same
743 * arguments as something we already accepted? If so, keep
744 * only the one that appears earlier in the search path.
746 * If we have an ordered list from SearchSysCacheList (the normal
747 * case), then any conflicting oper must immediately adjoin
748 * this one in the list, so we only need to look at the newest
749 * result item. If we have an unordered list, we have to scan
750 * the whole result list.
754 FuncCandidateList prevResult;
756 if (catlist->ordered)
758 if (operform->oprleft == resultList->args[0] &&
759 operform->oprright == resultList->args[1])
760 prevResult = resultList;
766 for (prevResult = resultList;
768 prevResult = prevResult->next)
770 if (operform->oprleft == prevResult->args[0] &&
771 operform->oprright == prevResult->args[1])
777 /* We have a match with a previous result */
778 Assert(pathpos != prevResult->pathpos);
779 if (pathpos > prevResult->pathpos)
780 continue; /* keep previous result */
781 /* replace previous result */
782 prevResult->pathpos = pathpos;
783 prevResult->oid = HeapTupleGetOid(opertup);
784 continue; /* args are same, of course */
790 * Okay to add it to result list
792 newResult = (FuncCandidateList) (resultSpace + nextResult);
793 nextResult += SPACE_PER_OP;
795 newResult->pathpos = pathpos;
796 newResult->oid = HeapTupleGetOid(opertup);
797 newResult->nargs = 2;
798 newResult->args[0] = operform->oprleft;
799 newResult->args[1] = operform->oprright;
800 newResult->next = resultList;
801 resultList = newResult;
804 ReleaseSysCacheList(catlist);
811 * Determine whether an operator (identified by OID) is visible in the
812 * current search path. Visible means "would be found by searching
813 * for the unqualified operator name with exact argument matches".
816 OperatorIsVisible(Oid oprid)
819 Form_pg_operator oprform;
823 oprtup = SearchSysCache(OPEROID,
824 ObjectIdGetDatum(oprid),
826 if (!HeapTupleIsValid(oprtup))
827 elog(ERROR, "cache lookup failed for operator %u", oprid);
828 oprform = (Form_pg_operator) GETSTRUCT(oprtup);
830 recomputeNamespacePath();
833 * Quick check: if it ain't in the path at all, it ain't visible.
834 * Items in the system namespace are surely in the path and so we
835 * needn't even do list_member_oid() for them.
837 oprnamespace = oprform->oprnamespace;
838 if (oprnamespace != PG_CATALOG_NAMESPACE &&
839 !list_member_oid(namespaceSearchPath, oprnamespace))
844 * If it is in the path, it might still not be visible; it could
845 * be hidden by another operator of the same name and arguments
846 * earlier in the path. So we must do a slow check to see if this
847 * is the same operator that would be found by
848 * OpernameGetCandidates.
850 char *oprname = NameStr(oprform->oprname);
851 FuncCandidateList clist;
855 clist = OpernameGetCandidates(list_make1(makeString(oprname)),
858 for (; clist; clist = clist->next)
860 if (clist->args[0] == oprform->oprleft &&
861 clist->args[1] == oprform->oprright)
863 /* Found the expected entry; is it the right op? */
864 visible = (clist->oid == oprid);
870 ReleaseSysCache(oprtup);
877 * OpclassGetCandidates
878 * Given an index access method OID, retrieve a list of all the
879 * opclasses for that AM that are visible in the search path.
881 * NOTE: the opcname_tmp field in the returned structs should not be used
882 * by callers, because it points at syscache entries that we release at
883 * the end of this routine. If any callers needed the name information,
884 * we could pstrdup() the names ... but at present it'd be wasteful.
887 OpclassGetCandidates(Oid amid)
889 OpclassCandidateList resultList = NULL;
893 /* Search syscache by AM OID only */
894 catlist = SearchSysCacheList(CLAAMNAMENSP, 1,
895 ObjectIdGetDatum(amid),
898 recomputeNamespacePath();
900 for (i = 0; i < catlist->n_members; i++)
902 HeapTuple opctup = &catlist->members[i]->tuple;
903 Form_pg_opclass opcform = (Form_pg_opclass) GETSTRUCT(opctup);
905 OpclassCandidateList newResult;
908 /* Consider only opclasses that are in the search path */
909 foreach(nsp, namespaceSearchPath)
911 if (opcform->opcnamespace == lfirst_oid(nsp))
916 continue; /* opclass is not in search path */
919 * Okay, it's in the search path, but does it have the same name
920 * as something we already accepted? If so, keep only the one
921 * that appears earlier in the search path.
923 * If we have an ordered list from SearchSysCacheList (the normal
924 * case), then any conflicting opclass must immediately adjoin
925 * this one in the list, so we only need to look at the newest
926 * result item. If we have an unordered list, we have to scan the
931 OpclassCandidateList prevResult;
933 if (catlist->ordered)
935 if (strcmp(NameStr(opcform->opcname),
936 resultList->opcname_tmp) == 0)
937 prevResult = resultList;
943 for (prevResult = resultList;
945 prevResult = prevResult->next)
947 if (strcmp(NameStr(opcform->opcname),
948 prevResult->opcname_tmp) == 0)
954 /* We have a match with a previous result */
955 Assert(pathpos != prevResult->pathpos);
956 if (pathpos > prevResult->pathpos)
957 continue; /* keep previous result */
958 /* replace previous result */
959 prevResult->opcname_tmp = NameStr(opcform->opcname);
960 prevResult->pathpos = pathpos;
961 prevResult->oid = HeapTupleGetOid(opctup);
962 prevResult->opcintype = opcform->opcintype;
963 prevResult->opcdefault = opcform->opcdefault;
964 prevResult->opckeytype = opcform->opckeytype;
970 * Okay to add it to result list
972 newResult = (OpclassCandidateList)
973 palloc(sizeof(struct _OpclassCandidateList));
974 newResult->opcname_tmp = NameStr(opcform->opcname);
975 newResult->pathpos = pathpos;
976 newResult->oid = HeapTupleGetOid(opctup);
977 newResult->opcintype = opcform->opcintype;
978 newResult->opcdefault = opcform->opcdefault;
979 newResult->opckeytype = opcform->opckeytype;
980 newResult->next = resultList;
981 resultList = newResult;
984 ReleaseSysCacheList(catlist);
990 * OpclassnameGetOpcid
991 * Try to resolve an unqualified index opclass name.
992 * Returns OID if opclass found in search path, else InvalidOid.
994 * This is essentially the same as TypenameGetTypid, but we have to have
995 * an extra argument for the index AM OID.
998 OpclassnameGetOpcid(Oid amid, const char *opcname)
1003 recomputeNamespacePath();
1005 foreach(l, namespaceSearchPath)
1007 Oid namespaceId = lfirst_oid(l);
1009 opcid = GetSysCacheOid(CLAAMNAMENSP,
1010 ObjectIdGetDatum(amid),
1011 PointerGetDatum(opcname),
1012 ObjectIdGetDatum(namespaceId),
1014 if (OidIsValid(opcid))
1018 /* Not found in path */
1024 * Determine whether an opclass (identified by OID) is visible in the
1025 * current search path. Visible means "would be found by searching
1026 * for the unqualified opclass name".
1029 OpclassIsVisible(Oid opcid)
1032 Form_pg_opclass opcform;
1036 opctup = SearchSysCache(CLAOID,
1037 ObjectIdGetDatum(opcid),
1039 if (!HeapTupleIsValid(opctup))
1040 elog(ERROR, "cache lookup failed for opclass %u", opcid);
1041 opcform = (Form_pg_opclass) GETSTRUCT(opctup);
1043 recomputeNamespacePath();
1046 * Quick check: if it ain't in the path at all, it ain't visible.
1047 * Items in the system namespace are surely in the path and so we
1048 * needn't even do list_member_oid() for them.
1050 opcnamespace = opcform->opcnamespace;
1051 if (opcnamespace != PG_CATALOG_NAMESPACE &&
1052 !list_member_oid(namespaceSearchPath, opcnamespace))
1057 * If it is in the path, it might still not be visible; it could
1058 * be hidden by another opclass of the same name earlier in the
1059 * path. So we must do a slow check to see if this opclass would
1060 * be found by OpclassnameGetOpcid.
1062 char *opcname = NameStr(opcform->opcname);
1064 visible = (OpclassnameGetOpcid(opcform->opcamid, opcname) == opcid);
1067 ReleaseSysCache(opctup);
1073 * ConversionGetConid
1074 * Try to resolve an unqualified conversion name.
1075 * Returns OID if conversion found in search path, else InvalidOid.
1077 * This is essentially the same as RelnameGetRelid.
1080 ConversionGetConid(const char *conname)
1085 recomputeNamespacePath();
1087 foreach(l, namespaceSearchPath)
1089 Oid namespaceId = lfirst_oid(l);
1091 conid = GetSysCacheOid(CONNAMENSP,
1092 PointerGetDatum(conname),
1093 ObjectIdGetDatum(namespaceId),
1095 if (OidIsValid(conid))
1099 /* Not found in path */
1104 * ConversionIsVisible
1105 * Determine whether a conversion (identified by OID) is visible in the
1106 * current search path. Visible means "would be found by searching
1107 * for the unqualified conversion name".
1110 ConversionIsVisible(Oid conid)
1113 Form_pg_conversion conform;
1117 contup = SearchSysCache(CONOID,
1118 ObjectIdGetDatum(conid),
1120 if (!HeapTupleIsValid(contup))
1121 elog(ERROR, "cache lookup failed for conversion %u", conid);
1122 conform = (Form_pg_conversion) GETSTRUCT(contup);
1124 recomputeNamespacePath();
1127 * Quick check: if it ain't in the path at all, it ain't visible.
1128 * Items in the system namespace are surely in the path and so we
1129 * needn't even do list_member_oid() for them.
1131 connamespace = conform->connamespace;
1132 if (connamespace != PG_CATALOG_NAMESPACE &&
1133 !list_member_oid(namespaceSearchPath, connamespace))
1138 * If it is in the path, it might still not be visible; it could
1139 * be hidden by another conversion of the same name earlier in the
1140 * path. So we must do a slow check to see if this conversion
1141 * would be found by ConversionGetConid.
1143 char *conname = NameStr(conform->conname);
1145 visible = (ConversionGetConid(conname) == conid);
1148 ReleaseSysCache(contup);
1154 * DeconstructQualifiedName
1155 * Given a possibly-qualified name expressed as a list of String nodes,
1156 * extract the schema name and object name.
1158 * *nspname_p is set to NULL if there is no explicit schema name.
1161 DeconstructQualifiedName(List *names,
1166 char *schemaname = NULL;
1167 char *objname = NULL;
1169 switch (list_length(names))
1172 objname = strVal(linitial(names));
1175 schemaname = strVal(linitial(names));
1176 objname = strVal(lsecond(names));
1179 catalogname = strVal(linitial(names));
1180 schemaname = strVal(lsecond(names));
1181 objname = strVal(lthird(names));
1184 * We check the catalog name and then ignore it.
1186 if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0)
1188 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1189 errmsg("cross-database references are not implemented: %s",
1190 NameListToString(names))));
1194 (errcode(ERRCODE_SYNTAX_ERROR),
1195 errmsg("improper qualified name (too many dotted names): %s",
1196 NameListToString(names))));
1200 *nspname_p = schemaname;
1201 *objname_p = objname;
1205 * LookupExplicitNamespace
1206 * Process an explicitly-specified schema name: look up the schema
1207 * and verify we have USAGE (lookup) rights in it.
1209 * Returns the namespace OID. Raises ereport if any problem.
1212 LookupExplicitNamespace(const char *nspname)
1215 AclResult aclresult;
1217 namespaceId = GetSysCacheOid(NAMESPACENAME,
1218 CStringGetDatum(nspname),
1220 if (!OidIsValid(namespaceId))
1222 (errcode(ERRCODE_UNDEFINED_SCHEMA),
1223 errmsg("schema \"%s\" does not exist", nspname)));
1225 aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
1226 if (aclresult != ACLCHECK_OK)
1227 aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
1234 * QualifiedNameGetCreationNamespace
1235 * Given a possibly-qualified name for an object (in List-of-Values
1236 * format), determine what namespace the object should be created in.
1237 * Also extract and return the object name (last component of list).
1239 * This is *not* used for tables. Hence, the TEMP table namespace is
1240 * never selected as the creation target.
1243 QualifiedNameGetCreationNamespace(List *names, char **objname_p)
1249 /* deconstruct the name list */
1250 DeconstructQualifiedName(names, &schemaname, &objname);
1254 /* use exact schema given */
1255 namespaceId = GetSysCacheOid(NAMESPACENAME,
1256 CStringGetDatum(schemaname),
1258 if (!OidIsValid(namespaceId))
1260 (errcode(ERRCODE_UNDEFINED_SCHEMA),
1261 errmsg("schema \"%s\" does not exist", schemaname)));
1262 /* we do not check for USAGE rights here! */
1266 /* use the default creation namespace */
1267 recomputeNamespacePath();
1268 namespaceId = defaultCreationNamespace;
1269 if (!OidIsValid(namespaceId))
1271 (errcode(ERRCODE_UNDEFINED_SCHEMA),
1272 errmsg("no schema has been selected to create in")));
1275 /* Note: callers will check for CREATE rights when appropriate */
1277 *objname_p = objname;
1282 * makeRangeVarFromNameList
1283 * Utility routine to convert a qualified-name list into RangeVar form.
1286 makeRangeVarFromNameList(List *names)
1288 RangeVar *rel = makeRangeVar(NULL, NULL);
1290 switch (list_length(names))
1293 rel->relname = strVal(linitial(names));
1296 rel->schemaname = strVal(linitial(names));
1297 rel->relname = strVal(lsecond(names));
1300 rel->catalogname = strVal(linitial(names));
1301 rel->schemaname = strVal(lsecond(names));
1302 rel->relname = strVal(lthird(names));
1306 (errcode(ERRCODE_SYNTAX_ERROR),
1307 errmsg("improper relation name (too many dotted names): %s",
1308 NameListToString(names))));
1317 * Utility routine to convert a qualified-name list into a string.
1319 * This is used primarily to form error messages, and so we do not quote
1320 * the list elements, for the sake of legibility.
1323 NameListToString(List *names)
1325 StringInfoData string;
1328 initStringInfo(&string);
1332 if (l != list_head(names))
1333 appendStringInfoChar(&string, '.');
1334 appendStringInfoString(&string, strVal(lfirst(l)));
1341 * NameListToQuotedString
1342 * Utility routine to convert a qualified-name list into a string.
1344 * Same as above except that names will be double-quoted where necessary,
1345 * so the string could be re-parsed (eg, by textToQualifiedNameList).
1348 NameListToQuotedString(List *names)
1350 StringInfoData string;
1353 initStringInfo(&string);
1357 if (l != list_head(names))
1358 appendStringInfoChar(&string, '.');
1359 appendStringInfoString(&string, quote_identifier(strVal(lfirst(l))));
1366 * isTempNamespace - is the given namespace my temporary-table namespace?
1369 isTempNamespace(Oid namespaceId)
1371 if (OidIsValid(myTempNamespace) && myTempNamespace == namespaceId)
1377 * isOtherTempNamespace - is the given namespace some other backend's
1378 * temporary-table namespace?
1381 isOtherTempNamespace(Oid namespaceId)
1386 /* If it's my own temp namespace, say "false" */
1387 if (isTempNamespace(namespaceId))
1389 /* Else, if the namespace name starts with "pg_temp_", say "true" */
1390 nspname = get_namespace_name(namespaceId);
1392 return false; /* no such namespace? */
1393 result = (strncmp(nspname, "pg_temp_", 8) == 0);
1399 * PushSpecialNamespace - push a "special" namespace onto the front of the
1402 * This is a slightly messy hack intended only for support of CREATE SCHEMA.
1403 * Although the API is defined to allow a stack of pushed namespaces, we
1404 * presently only support one at a time.
1406 * The pushed namespace will be removed from the search path at end of
1407 * transaction, whether commit or abort.
1410 PushSpecialNamespace(Oid namespaceId)
1412 Assert(!OidIsValid(mySpecialNamespace));
1413 mySpecialNamespace = namespaceId;
1414 namespaceSearchPathValid = false;
1418 * PopSpecialNamespace - remove previously pushed special namespace.
1421 PopSpecialNamespace(Oid namespaceId)
1423 Assert(mySpecialNamespace == namespaceId);
1424 mySpecialNamespace = InvalidOid;
1425 namespaceSearchPathValid = false;
1429 * FindConversionByName - find a conversion by possibly qualified name
1432 FindConversionByName(List *name)
1435 char *conversion_name;
1440 /* deconstruct the name list */
1441 DeconstructQualifiedName(name, &schemaname, &conversion_name);
1445 /* use exact schema given */
1446 namespaceId = LookupExplicitNamespace(schemaname);
1447 return FindConversion(conversion_name, namespaceId);
1451 /* search for it in search path */
1452 recomputeNamespacePath();
1454 foreach(l, namespaceSearchPath)
1456 namespaceId = lfirst_oid(l);
1457 conoid = FindConversion(conversion_name, namespaceId);
1458 if (OidIsValid(conoid))
1463 /* Not found in path */
1468 * FindDefaultConversionProc - find default encoding conversion proc
1471 FindDefaultConversionProc(int4 for_encoding, int4 to_encoding)
1476 recomputeNamespacePath();
1478 foreach(l, namespaceSearchPath)
1480 Oid namespaceId = lfirst_oid(l);
1482 proc = FindDefaultConversion(namespaceId, for_encoding, to_encoding);
1483 if (OidIsValid(proc))
1487 /* Not found in path */
1492 * recomputeNamespacePath - recompute path derived variables if needed.
1495 recomputeNamespacePath(void)
1497 AclId userId = GetUserId();
1504 MemoryContext oldcxt;
1507 * Do nothing if path is already valid.
1509 if (namespaceSearchPathValid && namespaceUser == userId)
1512 /* Need a modifiable copy of namespace_search_path string */
1513 rawname = pstrdup(namespace_search_path);
1515 /* Parse string into list of identifiers */
1516 if (!SplitIdentifierString(rawname, ',', &namelist))
1518 /* syntax error in name list */
1519 /* this should not happen if GUC checked check_search_path */
1520 elog(ERROR, "invalid list syntax");
1524 * Convert the list of names to a list of OIDs. If any names are not
1525 * recognizable or we don't have read access, just leave them out of
1526 * the list. (We can't raise an error, since the search_path setting
1527 * has already been accepted.) Don't make duplicate entries, either.
1530 foreach(l, namelist)
1532 char *curname = (char *) lfirst(l);
1535 if (strcmp(curname, "$user") == 0)
1537 /* $user --- substitute namespace matching user name, if any */
1540 tuple = SearchSysCache(SHADOWSYSID,
1541 ObjectIdGetDatum(userId),
1543 if (HeapTupleIsValid(tuple))
1547 uname = NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename);
1548 namespaceId = GetSysCacheOid(NAMESPACENAME,
1549 CStringGetDatum(uname),
1551 ReleaseSysCache(tuple);
1552 if (OidIsValid(namespaceId) &&
1553 !list_member_oid(oidlist, namespaceId) &&
1554 pg_namespace_aclcheck(namespaceId, userId,
1555 ACL_USAGE) == ACLCHECK_OK)
1556 oidlist = lappend_oid(oidlist, namespaceId);
1561 /* normal namespace reference */
1562 namespaceId = GetSysCacheOid(NAMESPACENAME,
1563 CStringGetDatum(curname),
1565 if (OidIsValid(namespaceId) &&
1566 !list_member_oid(oidlist, namespaceId) &&
1567 pg_namespace_aclcheck(namespaceId, userId,
1568 ACL_USAGE) == ACLCHECK_OK)
1569 oidlist = lappend_oid(oidlist, namespaceId);
1574 * Remember the first member of the explicit list.
1577 firstNS = InvalidOid;
1579 firstNS = linitial_oid(oidlist);
1582 * Add any implicitly-searched namespaces to the list. Note these go
1583 * on the front, not the back; also notice that we do not check USAGE
1584 * permissions for these.
1586 if (!list_member_oid(oidlist, PG_CATALOG_NAMESPACE))
1587 oidlist = lcons_oid(PG_CATALOG_NAMESPACE, oidlist);
1589 if (OidIsValid(myTempNamespace) &&
1590 !list_member_oid(oidlist, myTempNamespace))
1591 oidlist = lcons_oid(myTempNamespace, oidlist);
1593 if (OidIsValid(mySpecialNamespace) &&
1594 !list_member_oid(oidlist, mySpecialNamespace))
1595 oidlist = lcons_oid(mySpecialNamespace, oidlist);
1598 * Now that we've successfully built the new list of namespace OIDs,
1599 * save it in permanent storage.
1601 oldcxt = MemoryContextSwitchTo(TopMemoryContext);
1602 newpath = list_copy(oidlist);
1603 MemoryContextSwitchTo(oldcxt);
1605 /* Now safe to assign to state variable. */
1606 list_free(namespaceSearchPath);
1607 namespaceSearchPath = newpath;
1610 * Update info derived from search path.
1612 firstExplicitNamespace = firstNS;
1613 if (OidIsValid(mySpecialNamespace))
1614 defaultCreationNamespace = mySpecialNamespace;
1616 defaultCreationNamespace = firstNS;
1618 /* Mark the path valid. */
1619 namespaceSearchPathValid = true;
1620 namespaceUser = userId;
1624 list_free(namelist);
1629 * InitTempTableNamespace
1630 * Initialize temp table namespace on first use in a particular backend
1633 InitTempTableNamespace(void)
1635 char namespaceName[NAMEDATALEN];
1639 * First, do permission check to see if we are authorized to make temp
1640 * tables. We use a nonstandard error message here since
1641 * "databasename: permission denied" might be a tad cryptic.
1643 * Note that ACL_CREATE_TEMP rights are rechecked in pg_namespace_aclmask;
1644 * that's necessary since current user ID could change during the session.
1645 * But there's no need to make the namespace in the first place until a
1646 * temp table creation request is made by someone with appropriate rights.
1648 if (pg_database_aclcheck(MyDatabaseId, GetUserId(),
1649 ACL_CREATE_TEMP) != ACLCHECK_OK)
1651 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1652 errmsg("permission denied to create temporary tables in database \"%s\"",
1653 get_database_name(MyDatabaseId))));
1655 snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
1657 namespaceId = GetSysCacheOid(NAMESPACENAME,
1658 CStringGetDatum(namespaceName),
1660 if (!OidIsValid(namespaceId))
1663 * First use of this temp namespace in this database; create it.
1664 * The temp namespaces are always owned by the superuser. We
1665 * leave their permissions at default --- i.e., no access except
1666 * to superuser --- to ensure that unprivileged users can't peek
1667 * at other backends' temp tables. This works because the places
1668 * that access the temp namespace for my own backend skip
1669 * permissions checks on it.
1671 namespaceId = NamespaceCreate(namespaceName, BOOTSTRAP_USESYSID, 0);
1672 /* Advance command counter to make namespace visible */
1673 CommandCounterIncrement();
1678 * If the namespace already exists, clean it out (in case the
1679 * former owner crashed without doing so).
1681 RemoveTempRelations(namespaceId);
1685 * Okay, we've prepared the temp namespace ... but it's not committed
1686 * yet, so all our work could be undone by transaction rollback. Set
1687 * flag for AtEOXact_Namespace to know what to do.
1689 myTempNamespace = namespaceId;
1691 firstTempTransaction = true;
1693 namespaceSearchPathValid = false; /* need to rebuild list */
1697 * End-of-transaction cleanup for namespaces.
1700 AtEOXact_Namespace(bool isCommit)
1703 * If we abort the transaction in which a temp namespace was selected,
1704 * we'll have to do any creation or cleanout work over again. So,
1705 * just forget the namespace entirely until next time. On the other
1706 * hand, if we commit then register an exit callback to clean out the
1707 * temp tables at backend shutdown. (We only want to register the
1708 * callback once per session, so this is a good place to do it.)
1710 if (firstTempTransaction)
1713 on_shmem_exit(RemoveTempRelationsCallback, 0);
1716 myTempNamespace = InvalidOid;
1717 namespaceSearchPathValid = false; /* need to rebuild list */
1719 firstTempTransaction = false;
1723 * Clean up if someone failed to do PopSpecialNamespace
1725 if (OidIsValid(mySpecialNamespace))
1727 mySpecialNamespace = InvalidOid;
1728 namespaceSearchPathValid = false; /* need to rebuild list */
1733 * Remove all relations in the specified temp namespace.
1735 * This is called at backend shutdown (if we made any temp relations).
1736 * It is also called when we begin using a pre-existing temp namespace,
1737 * in order to clean out any relations that might have been created by
1738 * a crashed backend.
1741 RemoveTempRelations(Oid tempNamespaceId)
1743 ObjectAddress object;
1746 * We want to get rid of everything in the target namespace, but not
1747 * the namespace itself (deleting it only to recreate it later would
1748 * be a waste of cycles). We do this by finding everything that has a
1749 * dependency on the namespace.
1751 object.classId = get_system_catalog_relid(NamespaceRelationName);
1752 object.objectId = tempNamespaceId;
1753 object.objectSubId = 0;
1755 deleteWhatDependsOn(&object, false);
1759 * Callback to remove temp relations at backend exit.
1762 RemoveTempRelationsCallback(int code, Datum arg)
1764 if (OidIsValid(myTempNamespace)) /* should always be true */
1766 /* Need to ensure we have a usable transaction. */
1767 AbortOutOfAnyTransaction();
1768 StartTransactionCommand();
1770 RemoveTempRelations(myTempNamespace);
1772 CommitTransactionCommand();
1778 * Routines for handling the GUC variable 'search_path'.
1781 /* assign_hook: validate new search_path, do extra actions as needed */
1783 assign_search_path(const char *newval, bool doit, GucSource source)
1789 /* Need a modifiable copy of string */
1790 rawname = pstrdup(newval);
1792 /* Parse string into list of identifiers */
1793 if (!SplitIdentifierString(rawname, ',', &namelist))
1795 /* syntax error in name list */
1797 list_free(namelist);
1802 * If we aren't inside a transaction, we cannot do database access so
1803 * cannot verify the individual names. Must accept the list on faith.
1805 if (source >= PGC_S_INTERACTIVE && IsTransactionState())
1808 * Verify that all the names are either valid namespace names or
1809 * "$user". We do not require $user to correspond to a valid
1810 * namespace. We do not check for USAGE rights, either; should
1813 * When source == PGC_S_TEST, we are checking the argument of an
1814 * ALTER DATABASE SET or ALTER USER SET command. It could be that
1815 * the intended use of the search path is for some other database,
1816 * so we should not error out if it mentions schemas not present
1817 * in the current database. We reduce the message to NOTICE instead.
1819 foreach(l, namelist)
1821 char *curname = (char *) lfirst(l);
1823 if (strcmp(curname, "$user") == 0)
1825 if (!SearchSysCacheExists(NAMESPACENAME,
1826 CStringGetDatum(curname),
1828 ereport((source == PGC_S_TEST) ? NOTICE : ERROR,
1829 (errcode(ERRCODE_UNDEFINED_SCHEMA),
1830 errmsg("schema \"%s\" does not exist", curname)));
1835 list_free(namelist);
1838 * We mark the path as needing recomputation, but don't do anything
1839 * until it's needed. This avoids trying to do database access during
1840 * GUC initialization.
1843 namespaceSearchPathValid = false;
1849 * InitializeSearchPath: initialize module during InitPostgres.
1851 * This is called after we are up enough to be able to do catalog lookups.
1854 InitializeSearchPath(void)
1856 if (IsBootstrapProcessingMode())
1859 * In bootstrap mode, the search path must be 'pg_catalog' so that
1860 * tables are created in the proper namespace; ignore the GUC
1863 MemoryContext oldcxt;
1865 oldcxt = MemoryContextSwitchTo(TopMemoryContext);
1866 namespaceSearchPath = list_make1_oid(PG_CATALOG_NAMESPACE);
1867 MemoryContextSwitchTo(oldcxt);
1868 defaultCreationNamespace = PG_CATALOG_NAMESPACE;
1869 firstExplicitNamespace = PG_CATALOG_NAMESPACE;
1870 namespaceSearchPathValid = true;
1871 namespaceUser = GetUserId();
1876 * In normal mode, arrange for a callback on any syscache
1877 * invalidation of pg_namespace rows.
1879 CacheRegisterSyscacheCallback(NAMESPACEOID,
1882 /* Force search path to be recomputed on next use */
1883 namespaceSearchPathValid = false;
1889 * Syscache inval callback function
1892 NamespaceCallback(Datum arg, Oid relid)
1894 /* Force search path to be recomputed on next use */
1895 namespaceSearchPathValid = false;
1899 * Fetch the active search path. The return value is a palloc'ed list
1900 * of OIDs; the caller is responsible for freeing this storage as
1903 * The returned list includes the implicitly-prepended namespaces only if
1904 * includeImplicit is true.
1907 fetch_search_path(bool includeImplicit)
1911 recomputeNamespacePath();
1913 result = list_copy(namespaceSearchPath);
1914 if (!includeImplicit)
1916 while (result && linitial_oid(result) != firstExplicitNamespace)
1917 result = list_delete_first(result);
1924 * Export the FooIsVisible functions as SQL-callable functions.
1928 pg_table_is_visible(PG_FUNCTION_ARGS)
1930 Oid oid = PG_GETARG_OID(0);
1932 PG_RETURN_BOOL(RelationIsVisible(oid));
1936 pg_type_is_visible(PG_FUNCTION_ARGS)
1938 Oid oid = PG_GETARG_OID(0);
1940 PG_RETURN_BOOL(TypeIsVisible(oid));
1944 pg_function_is_visible(PG_FUNCTION_ARGS)
1946 Oid oid = PG_GETARG_OID(0);
1948 PG_RETURN_BOOL(FunctionIsVisible(oid));
1952 pg_operator_is_visible(PG_FUNCTION_ARGS)
1954 Oid oid = PG_GETARG_OID(0);
1956 PG_RETURN_BOOL(OperatorIsVisible(oid));
1960 pg_opclass_is_visible(PG_FUNCTION_ARGS)
1962 Oid oid = PG_GETARG_OID(0);
1964 PG_RETURN_BOOL(OpclassIsVisible(oid));
1968 pg_conversion_is_visible(PG_FUNCTION_ARGS)
1970 Oid oid = PG_GETARG_OID(0);
1972 PG_RETURN_BOOL(ConversionIsVisible(oid));