#include "postgres.h"

#include "catalog/dependency.h"
#include "fmgr.h"
#include "utils/builtins.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

Datum describe_object(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(describe_object);

Datum
describe_object(PG_FUNCTION_ARGS)
{
	Oid		classid = PG_GETARG_OID(0);
	Oid		objid = PG_GETARG_OID(1);
	int32	subobjid = PG_GETARG_INT32(2);
	ObjectAddress	address;
	char   *description = NULL;

	if (classid != InvalidOid)
	{
		address.classId = classid;
		address.objectId = objid;
		address.objectSubId = subobjid;

		description = getObjectDescription(&address);
	}

	if (!description || description[0] == '\0')
		PG_RETURN_NULL();

	PG_RETURN_TEXT_P(cstring_to_text(description));
}
