|
13 | 13 | * Portions Copyright (c) 1994, Regents of the University of California
|
14 | 14 | *
|
15 | 15 | * IDENTIFICATION
|
16 |
| - * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.41 2002/12/04 05:18:31 momjian Exp $ |
| 16 | + * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.42 2002/12/12 21:02:19 momjian Exp $ |
17 | 17 | *
|
18 | 18 | *-------------------------------------------------------------------------
|
19 | 19 | */
|
@@ -143,7 +143,7 @@ Datum pg_type_is_visible(PG_FUNCTION_ARGS);
|
143 | 143 | Datum pg_function_is_visible(PG_FUNCTION_ARGS);
|
144 | 144 | Datum pg_operator_is_visible(PG_FUNCTION_ARGS);
|
145 | 145 | Datum pg_opclass_is_visible(PG_FUNCTION_ARGS);
|
146 |
| - |
| 146 | +Datum pg_conversion_is_visible(PG_FUNCTION_ARGS); |
147 | 147 |
|
148 | 148 | /*
|
149 | 149 | * RangeVarGetRelid
|
@@ -1035,6 +1035,87 @@ OpclassIsVisible(Oid opcid)
|
1035 | 1035 | return visible;
|
1036 | 1036 | }
|
1037 | 1037 |
|
| 1038 | +/* |
| 1039 | + * ConversionGetConid |
| 1040 | + * Try to resolve an unqualified conversion name. |
| 1041 | + * Returns OID if conversion found in search path, else InvalidOid. |
| 1042 | + * |
| 1043 | + * This is essentially the same as RelnameGetRelid. |
| 1044 | + */ |
| 1045 | +Oid |
| 1046 | +ConversionGetConid(const char *conname) |
| 1047 | +{ |
| 1048 | + Oid conid; |
| 1049 | + List *lptr; |
| 1050 | + |
| 1051 | + recomputeNamespacePath(); |
| 1052 | + |
| 1053 | + foreach(lptr, namespaceSearchPath) |
| 1054 | + { |
| 1055 | + Oid namespaceId = (Oid) lfirsti(lptr); |
| 1056 | + |
| 1057 | + conid = GetSysCacheOid(CONNAMENSP, |
| 1058 | + PointerGetDatum(conname), |
| 1059 | + ObjectIdGetDatum(namespaceId), |
| 1060 | + 0, 0); |
| 1061 | + if (OidIsValid(conid)) |
| 1062 | + return conid; |
| 1063 | + } |
| 1064 | + |
| 1065 | + /* Not found in path */ |
| 1066 | + return InvalidOid; |
| 1067 | +} |
| 1068 | + |
| 1069 | +/* |
| 1070 | + * ConversionIsVisible |
| 1071 | + * Determine whether a conversion (identified by OID) is visible in the |
| 1072 | + * current search path. Visible means "would be found by searching |
| 1073 | + * for the unqualified conversion name". |
| 1074 | + */ |
| 1075 | +bool |
| 1076 | +ConversionIsVisible(Oid conid) |
| 1077 | +{ |
| 1078 | + HeapTuple contup; |
| 1079 | + Form_pg_conversion conform; |
| 1080 | + Oid connamespace; |
| 1081 | + bool visible; |
| 1082 | + |
| 1083 | + contup = SearchSysCache(CONOID, |
| 1084 | + ObjectIdGetDatum(conid), |
| 1085 | + 0, 0, 0); |
| 1086 | + if (!HeapTupleIsValid(contup)) |
| 1087 | + elog(ERROR, "Cache lookup failed for converions %u", conid); |
| 1088 | + conform = (Form_pg_conversion) GETSTRUCT(contup); |
| 1089 | + |
| 1090 | + recomputeNamespacePath(); |
| 1091 | + |
| 1092 | + /* |
| 1093 | + * Quick check: if it ain't in the path at all, it ain't visible. |
| 1094 | + * Items in the system namespace are surely in the path and so we |
| 1095 | + * needn't even do intMember() for them. |
| 1096 | + */ |
| 1097 | + connamespace = conform->connamespace; |
| 1098 | + if (connamespace != PG_CATALOG_NAMESPACE && |
| 1099 | + !intMember(connamespace, namespaceSearchPath)) |
| 1100 | + visible = false; |
| 1101 | + else |
| 1102 | + { |
| 1103 | + /* |
| 1104 | + * If it is in the path, it might still not be visible; it could |
| 1105 | + * be hidden by another conversion of the same name earlier in the |
| 1106 | + * path. So we must do a slow check to see if this conversion would |
| 1107 | + * be found by ConvnameGetConid. |
| 1108 | + */ |
| 1109 | + char *conname = NameStr(conform->conname); |
| 1110 | + |
| 1111 | + visible = (ConversionGetConid(conname) == conid); |
| 1112 | + } |
| 1113 | + |
| 1114 | + ReleaseSysCache(contup); |
| 1115 | + |
| 1116 | + return visible; |
| 1117 | +} |
| 1118 | + |
1038 | 1119 | /*
|
1039 | 1120 | * DeconstructQualifiedName
|
1040 | 1121 | * Given a possibly-qualified name expressed as a list of String nodes,
|
@@ -1854,3 +1935,11 @@ pg_opclass_is_visible(PG_FUNCTION_ARGS)
|
1854 | 1935 |
|
1855 | 1936 | PG_RETURN_BOOL(OpclassIsVisible(oid));
|
1856 | 1937 | }
|
| 1938 | + |
| 1939 | +Datum |
| 1940 | +pg_conversion_is_visible(PG_FUNCTION_ARGS) |
| 1941 | +{ |
| 1942 | + Oid oid = PG_GETARG_OID(0); |
| 1943 | + |
| 1944 | + PG_RETURN_BOOL(ConversionIsVisible(oid)); |
| 1945 | +} |
0 commit comments