These are tools that make it easier to interface with the Postgres catalog tables/views/functions. They are meant for use by code, not by people.
To make use of them, you need to grant cat_tools__usage to any roles that need access.
Warning | Any function or view in this extension that exposes raw PostgreSQL catalog
information does not provide a stable API. The PostgreSQL system catalogs
change between major versions — columns are added, removed, and change type.
If your code depends on the specific columns returned by objects such as
|
This is very much a work in progress. If it doesn’t do something you need, please open an issue!
Usually just run ALTER EXTENSION cat_tools UPDATE. Two special cases apply to a
database that reached 0.2.2 via the 0.2.0/0.2.1 update scripts, whose catalog
views are broken (they still reference pg_class/pg_attribute columns —
relhasoids, relhaspkey — that a fresh 0.2.2 install correctly omits). A fresh
0.2.2 install has correct views and is unaffected by either case.
Update the extension to 0.2.3 (or newer) on the old cluster first, then run
binary pg_upgrade. The broken views reference catalog columns removed in PG12+,
so pg_upgrade fails otherwise; the 0.2.2→0.2.3 update repairs them first. See
the 0.2.3 entry in HISTORY.asc for details.
Only when the views are broken, the 0.2.2→0.2.3 update DROP+CREATE`s (without
`CASCADE) these public objects: cat_tools.pg_class_v, cat_tools.column, and
the cat_tools.pg_class(regclass) function. If you created your own objects
depending on any of these, drop them before updating and recreate them afterward;
the update aborts otherwise. A fresh 0.2.2 install’s views are left untouched, so
its dependents are unaffected. See the 0.2.3 entry in HISTORY.asc for details.
object_type- Descriptive names for every type of Postgres object (table, operator, rule, etc)constraint_type- Types of constraints (domain constraintortable_constraint)relation_type- Types of objects stored inpg_classrelation_relkind- Valid values forpg_class.relkindroutine_type- Types of routines stored inpg_procroutine_argument_mode- Argument modes for function/procedure parametersroutine_volatility- Volatility levels for functions/proceduresroutine_parallel_safety- Parallel safety levels for functions/proceduresroutine_argument- Detailed information about a single function/procedure argument
enum_range(regtype)- Returns valid values for an ENUM as an arrayenum_range_srf(regtype)- Returns valid values for an ENUM as a recordsetname__check(text)- Throws an error if input would be truncated when cast to namepg_class(relation regclass)- Returns pg_class_v row for a relationpg_extension__get(extension_name name)- Returns pg_extension_v row for an extensionextension__schemas(extension_names text/name[])- Returns the schemas for the requested functionsextension__schemas_unique(extension_names text/name[])- Returns a unique array of schemaspg_attribute__get(relation regclass, column_name name)- Returnspg_attributerow for a column; throws error if column doesn’t existrelation__column_names(relation regclass)- Returns an array of quoted column names for a relation in ordinal position orderrelation__is_catalog(relation regclass)- Returns true if the relation is in thepg_catalogschemarelation__is_temp(relation regclass)- Returns true if the relation is a temporary table (lives in a schema that starts with 'pg_temp')
Functions for working with object_type values — the enum of descriptive names for every type of Postgres object (table, index, role, etc).
object__catalog(object_type)- Returns catalog table that is used to storeobject_typeobjectsobject__reg_type(object_catalog)- Returns the "reg" pseudotype (ie: regclass) associated with a system catalog (ie: pg_class)objectreg_type_catalog(object_identifier_type regtype)- Returns the system catalog that stores a particular object identifier type (inverse ofobjectreg_type)object__address_classid(object_type)- Returns the classid used by thepg_*_object*()functions for an object_typeobjects__shared()- Returns an array of object types that are shared catalog objects (as opposed to per-database)objectsshared_srf()- Set returning version ofobjectssharedobject__is_shared(object_type)- Returns true if object_type is a shared objectobjects__address_unsupported()- Returns array of object types not supported bypg_get_object_address()objectsaddress_unsupported_srf()- Set returning version ofobjectsaddress_unsupportedobject__is_address_unsupported(object_type)- Returns true if object type is not supported bypg_get_object_address()
get_serial_sequence(table_name text, column_name text)- Returns sequence associated with a column; unlikepg_get_serial_sequence, throws an exception if no sequence existscurrval(table_name text, column_name text)- Alias forsequence__lastnextval(table_name text, column_name text)- Alias forsequence__nextsetval(table_name text, column_name text, new_value bigint, has_been_used boolean DEFAULT true)- Sets sequence value for a column; ifhas_been_usedis true, sequence will returnnew_value + 1nextsequence__last(table_name text, column_name text)- Returns the last value assigned to a column’s sequencesequence__next(table_name text, column_name text)- Returns the next sequence value and advances the sequencesequence__set_last(table_name text, column_name text, last_value bigint)- Sets last used value; sequence will returnlast_value + 1nextsequence__set_next(table_name text, column_name text, next_value bigint)- Sets the next value the sequence will return
routine__parse_arg_types(arguments)- Accepts full function argument string and returns regtype[] of IN/INOUT argumentsroutineparse_arg_types_text(arguments)- Version ofroutineparse_arg_typesthat returns textroutine__parse_arg_names(arguments)- Accepts full function argument string and returns text[] of IN/INOUT argument namesroutineparse_arg_names_text(arguments)- Version ofroutineparse_arg_namesthat returns textroutine__arg_types(regprocedure)- Returns argument types for a function as regtype[]routinearg_types_text(regprocedure)- Version ofroutinearg_typesthat returns textroutine__arg_names(regprocedure)- Returns argument names for a function as text[]routinearg_names_text(regprocedure)- Version ofroutinearg_namesthat returns textregprocedure(routine_name, arguments)- Returns regprocedure for routine_name and its full set of arguments
triggerargs_as_text(text)- Converts the arguments for a trigger function (as returned bytriggerparse()) to text (for backwards compatibility).trigger__get_oid(trigger_table, trigger_name)- oid of a trigger. Throws error if trigger doesn’t exits.triggerget_oidloose(trigger_table, trigger_name)- oid of a trigger. Does not throw error if trigger doesn’t exits.trigger__parse(trigger oid)- Returns information about a triggertrigger__parse(table_name regclass, trigger_name text)- Returns information about a trigger
relation__kind(relkind)- Mapping frompg_class.relkindto arelation_typerelation__relkind(relation_type)- Mapping fromrelation_typeto apg_class.relkindvalueroutine__type(prokind)- Mapping frompg_proc.prokindtoroutine_typeroutine__argument_mode(mode)- Mapping frompg_proc.proargmodeselement toroutine_argument_moderoutine__volatility(volatile)- Mapping frompg_proc.provolatiletoroutine_volatilityroutine__parallel_safety(parallel)- Mapping frompg_proc.proparalleltoroutine_parallel_safety
functionarg_types(arguments)- DEPRECATED: Useroutineparse_arg_typesinsteadfunctionarg_types_text(arguments)- DEPRECATED: Useroutineparse_arg_types_textinstead
Warning | These views may eventually move into a separate extension! |
pg_class_v- Joins pg_class to pg_namespacepg_extension_v- Joins pg_extension to pg_namespace; cast extconfig to regclass[]column- Returns data about columnspg_all_foreign_keys- Data about foreign keys
Cat Tools is released under a MIT license.
Copyright (c) 2016-2026 Jim Nasby <Jim.Nasby@gmail.com>.