Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cc2deb

Browse files
committed
Add pg_describe_object function
This function is useful to obtain textual descriptions of objects asstored in pg_depend.
1 parent48c348f commit6cc2deb

File tree

5 files changed

+48
-28
lines changed

5 files changed

+48
-28
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12847,6 +12847,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1284712847
<entry><type>setof oid</type></entry>
1284812848
<entry>get the set of database OIDs that have objects in the tablespace</entry>
1284912849
</row>
12850+
<row>
12851+
<entry><literal><function>pg_describe_object(<parameter>catalog_id</parameter>, <parameter>object_id</parameter>, <parameter>object_sub_id</parameter>)</function>)</literal></entry>
12852+
<entry><type>text</type></entry>
12853+
<entry>get description of a database object</entry>
12854+
</row>
1285012855
<row>
1285112856
<entry><literal><function>pg_typeof(<parameter>any</parameter>)</function></literal></entry>
1285212857
<entry><type>regtype</type></entry>
@@ -12940,6 +12945,13 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
1294012945
<structname>pg_class</> catalogs.
1294112946
</para>
1294212947

12948+
<para>
12949+
<function>pg_describe_object</function> returns a description of a database
12950+
object specified by catalog OID, object OID and a (possibly zero) sub-object ID.
12951+
This is useful to determine the identity of an object as stored in the
12952+
<structname>pg_depend</structname> catalog.
12953+
</para>
12954+
1294312955
<para>
1294412956
<function>pg_typeof</function> returns the OID of the data type of the
1294512957
value that is passed to it. This can be helpful for troubleshooting or

‎src/backend/catalog/dependency.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,118 +1982,97 @@ free_object_addresses(ObjectAddresses *addrs)
19821982
ObjectClass
19831983
getObjectClass(constObjectAddress*object)
19841984
{
1985+
/* only pg_class entries can have nonzero objectSubId */
1986+
if (object->classId!=RelationRelationId&&
1987+
object->objectSubId!=0)
1988+
elog(ERROR,"invalid objectSubId 0 for object class %u",
1989+
object->classId);
1990+
19851991
switch (object->classId)
19861992
{
19871993
caseRelationRelationId:
19881994
/* caller must check objectSubId */
19891995
returnOCLASS_CLASS;
19901996

19911997
caseProcedureRelationId:
1992-
Assert(object->objectSubId==0);
19931998
returnOCLASS_PROC;
19941999

19952000
caseTypeRelationId:
1996-
Assert(object->objectSubId==0);
19972001
returnOCLASS_TYPE;
19982002

19992003
caseCastRelationId:
2000-
Assert(object->objectSubId==0);
20012004
returnOCLASS_CAST;
20022005

20032006
caseConstraintRelationId:
2004-
Assert(object->objectSubId==0);
20052007
returnOCLASS_CONSTRAINT;
20062008

20072009
caseConversionRelationId:
2008-
Assert(object->objectSubId==0);
20092010
returnOCLASS_CONVERSION;
20102011

20112012
caseAttrDefaultRelationId:
2012-
Assert(object->objectSubId==0);
20132013
returnOCLASS_DEFAULT;
20142014

20152015
caseLanguageRelationId:
2016-
Assert(object->objectSubId==0);
20172016
returnOCLASS_LANGUAGE;
20182017

20192018
caseLargeObjectRelationId:
2020-
Assert(object->objectSubId==0);
20212019
returnOCLASS_LARGEOBJECT;
20222020

20232021
caseOperatorRelationId:
2024-
Assert(object->objectSubId==0);
20252022
returnOCLASS_OPERATOR;
20262023

20272024
caseOperatorClassRelationId:
2028-
Assert(object->objectSubId==0);
20292025
returnOCLASS_OPCLASS;
20302026

20312027
caseOperatorFamilyRelationId:
2032-
Assert(object->objectSubId==0);
20332028
returnOCLASS_OPFAMILY;
20342029

20352030
caseAccessMethodOperatorRelationId:
2036-
Assert(object->objectSubId==0);
20372031
returnOCLASS_AMOP;
20382032

20392033
caseAccessMethodProcedureRelationId:
2040-
Assert(object->objectSubId==0);
20412034
returnOCLASS_AMPROC;
20422035

20432036
caseRewriteRelationId:
2044-
Assert(object->objectSubId==0);
20452037
returnOCLASS_REWRITE;
20462038

20472039
caseTriggerRelationId:
2048-
Assert(object->objectSubId==0);
20492040
returnOCLASS_TRIGGER;
20502041

20512042
caseNamespaceRelationId:
2052-
Assert(object->objectSubId==0);
20532043
returnOCLASS_SCHEMA;
20542044

20552045
caseTSParserRelationId:
2056-
Assert(object->objectSubId==0);
20572046
returnOCLASS_TSPARSER;
20582047

20592048
caseTSDictionaryRelationId:
2060-
Assert(object->objectSubId==0);
20612049
returnOCLASS_TSDICT;
20622050

20632051
caseTSTemplateRelationId:
2064-
Assert(object->objectSubId==0);
20652052
returnOCLASS_TSTEMPLATE;
20662053

20672054
caseTSConfigRelationId:
2068-
Assert(object->objectSubId==0);
20692055
returnOCLASS_TSCONFIG;
20702056

20712057
caseAuthIdRelationId:
2072-
Assert(object->objectSubId==0);
20732058
returnOCLASS_ROLE;
20742059

20752060
caseDatabaseRelationId:
2076-
Assert(object->objectSubId==0);
20772061
returnOCLASS_DATABASE;
20782062

20792063
caseTableSpaceRelationId:
2080-
Assert(object->objectSubId==0);
20812064
returnOCLASS_TBLSPACE;
20822065

20832066
caseForeignDataWrapperRelationId:
2084-
Assert(object->objectSubId==0);
20852067
returnOCLASS_FDW;
20862068

20872069
caseForeignServerRelationId:
2088-
Assert(object->objectSubId==0);
20892070
returnOCLASS_FOREIGN_SERVER;
20902071

20912072
caseUserMappingRelationId:
2092-
Assert(object->objectSubId==0);
20932073
returnOCLASS_USER_MAPPING;
20942074

20952075
caseDefaultAclRelationId:
2096-
Assert(object->objectSubId==0);
20972076
returnOCLASS_DEFACL;
20982077
}
20992078

@@ -2807,3 +2786,27 @@ getOpFamilyDescription(StringInfo buffer, Oid opfid)
28072786
ReleaseSysCache(amTup);
28082787
ReleaseSysCache(opfTup);
28092788
}
2789+
2790+
/*
2791+
* SQL-level callable version of getObjectDescription
2792+
*/
2793+
Datum
2794+
pg_describe_object(PG_FUNCTION_ARGS)
2795+
{
2796+
Oidclassid=PG_GETARG_OID(0);
2797+
Oidobjid=PG_GETARG_OID(1);
2798+
int32subobjid=PG_GETARG_INT32(2);
2799+
char*description=NULL;
2800+
ObjectAddressaddress;
2801+
2802+
/* for "pinned" items in pg_depend, return null */
2803+
if (!OidIsValid(classid)&& !OidIsValid(objid))
2804+
PG_RETURN_NULL();
2805+
2806+
address.classId=classid;
2807+
address.objectId=objid;
2808+
address.objectSubId=subobjid;
2809+
2810+
description=getObjectDescription(&address);
2811+
PG_RETURN_TEXT_P(cstring_to_text(description));
2812+
}

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201011151
56+
#defineCATALOG_VERSION_NO201011181
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,6 +3333,8 @@ DESCR("view system lock information");
33333333
DATA(insertOID=1065 (pg_prepared_xactPGNSPPGUID12110000fffttv002249"""{28,25,1184,26,26}""{o,o,o,o,o}""{transaction,gid,prepared,ownerid,dbid}"_null_pg_prepared_xact_null__null__null_ ));
33343334
DESCR("view two-phase transactions");
33353335

3336+
DATA(insertOID=3537 (pg_describe_objectPGNSPPGUID12100ffftfs3025"26 26 23"_null__null__null__null_pg_describe_object_null__null__null_ ));
3337+
33363338
DATA(insertOID=2079 (pg_table_is_visiblePGNSPPGUID12100ffftfs1016"26"_null__null__null__null_pg_table_is_visible_null__null__null_ ));
33373339
DESCR("is table visible in search path?");
33383340
DATA(insertOID=2080 (pg_type_is_visiblePGNSPPGUID12100ffftfs1016"26"_null__null__null__null_pg_type_is_visible_null__null__null_ ));

‎src/include/utils/builtins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@ extern Datum window_nth_value(PG_FUNCTION_ARGS);
10451045
/* access/transam/twophase.c */
10461046
externDatumpg_prepared_xact(PG_FUNCTION_ARGS);
10471047

1048+
/* catalogs/dependency.c */
1049+
externDatumpg_describe_object(PG_FUNCTION_ARGS);
1050+
10481051
/* commands/constraint.c */
10491052
externDatumunique_key_recheck(PG_FUNCTION_ARGS);
10501053

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp