9.26. System Information Functions and Operators (original) (raw)

Function Description
format_type ( type oid, typemod integer ) → text Returns the SQL name for a data type that is identified by its type OID and possibly a type modifier. Pass NULL for the type modifier if no specific modifier is known.
pg_get_constraintdef ( constraint oid [, pretty boolean ] ) → text Reconstructs the creating command for a constraint. (This is a decompiled reconstruction, not the original text of the command.)
pg_get_expr ( expr pg_node_tree, relation oid [, pretty boolean ] ) → text Decompiles the internal form of an expression stored in the system catalogs, such as the default value for a column. If the expression might contain Vars, specify the OID of the relation they refer to as the second parameter; if no Vars are expected, passing zero is sufficient.
pg_get_functiondef ( func oid ) → text Reconstructs the creating command for a function or procedure. (This is a decompiled reconstruction, not the original text of the command.) The result is a complete CREATE OR REPLACE FUNCTION or CREATE OR REPLACE PROCEDURE statement.
pg_get_function_arguments ( func oid ) → text Reconstructs the argument list of a function or procedure, in the form it would need to appear in within CREATE FUNCTION (including default values).
pg_get_function_identity_arguments ( func oid ) → text Reconstructs the argument list necessary to identify a function or procedure, in the form it would need to appear in within commands such as ALTER FUNCTION. This form omits default values.
pg_get_function_result ( func oid ) → text Reconstructs the RETURNS clause of a function, in the form it would need to appear in within CREATE FUNCTION. Returns NULL for a procedure.
pg_get_indexdef ( index oid [, column integer, pretty boolean ] ) → text Reconstructs the creating command for an index. (This is a decompiled reconstruction, not the original text of the command.) If column is supplied and is not zero, only the definition of that column is reconstructed.
pg_get_keywords () → setof record ( word text, catcode "char", catdesc text ) Returns a set of records describing the SQL keywords recognized by the server. The word column contains the keyword. The catcode column contains a category code: U for an unreserved keyword, C for a keyword that can be a column name, T for a keyword that can be a type or function name, or R for a fully reserved keyword. The catdesc column contains a possibly-localized string describing the category.
pg_get_ruledef ( rule oid [, pretty boolean ] ) → text Reconstructs the creating command for a rule. (This is a decompiled reconstruction, not the original text of the command.)
pg_get_serial_sequence ( table text, column text ) → text Returns the name of the sequence associated with a column, or NULL if no sequence is associated with the column. If the column is an identity column, the associated sequence is the sequence internally created for that column. For columns created using one of the serial types (serial, smallserial, bigserial), it is the sequence created for that serial column definition. In the latter case, the association can be modified or removed with ALTER SEQUENCE OWNED BY. (This function probably should have been called pg_get_owned_sequence; its current name reflects the fact that it has historically been used with serial-type columns.) The first parameter is a table name with optional schema, and the second parameter is a column name. Because the first parameter potentially contains both schema and table names, it is parsed per usual SQL rules, meaning it is lower-cased by default. The second parameter, being just a column name, is treated literally and so has its case preserved. The result is suitably formatted for passing to the sequence functions (see Section 9.17). A typical use is in reading the current value of the sequence for an identity or serial column, for example: SELECT currval(pg_get_serial_sequence('sometable', 'id'));
pg_get_statisticsobjdef ( statobj oid ) → text Reconstructs the creating command for an extended statistics object. (This is a decompiled reconstruction, not the original text of the command.)
pg_get_triggerdef ( trigger oid [, pretty boolean ] ) → text Reconstructs the creating command for a trigger. (This is a decompiled reconstruction, not the original text of the command.)
pg_get_userbyid ( role oid ) → name Returns a role's name given its OID.
pg_get_viewdef ( view oid [, pretty boolean ] ) → text Reconstructs the underlying SELECT command for a view or materialized view. (This is a decompiled reconstruction, not the original text of the command.)
pg_get_viewdef ( view oid, wrap_column integer ) → text Reconstructs the underlying SELECT command for a view or materialized view. (This is a decompiled reconstruction, not the original text of the command.) In this form of the function, pretty-printing is always enabled, and long lines are wrapped to try to keep them shorter than the specified number of columns.
pg_get_viewdef ( view text [, pretty boolean ] ) → text Reconstructs the underlying SELECT command for a view or materialized view, working from a textual name for the view rather than its OID. (This is deprecated; use the OID variant instead.)
pg_index_column_has_property ( index regclass, column integer, property text ) → boolean Tests whether an index column has the named property. Common index column properties are listed in Table 9.69. (Note that extension access methods can define additional property names for their indexes.) NULL is returned if the property name is not known or does not apply to the particular object, or if the OID or column number does not identify a valid object.
pg_index_has_property ( index regclass, property text ) → boolean Tests whether an index has the named property. Common index properties are listed in Table 9.70. (Note that extension access methods can define additional property names for their indexes.) NULL is returned if the property name is not known or does not apply to the particular object, or if the OID does not identify a valid object.
pg_indexam_has_property ( am oid, property text ) → boolean Tests whether an index access method has the named property. Access method properties are listed in Table 9.71. NULL is returned if the property name is not known or does not apply to the particular object, or if the OID does not identify a valid object.
pg_options_to_table ( options_array text[] ) → setof record ( option_name text, option_value text ) Returns the set of storage options represented by a value from pg_class.reloptions or pg_attribute.attoptions.
pg_tablespace_databases ( tablespace oid ) → setof oid Returns the set of OIDs of databases that have objects stored in the specified tablespace. If this function returns any rows, the tablespace is not empty and cannot be dropped. To identify the specific objects populating the tablespace, you will need to connect to the database(s) identified by pg_tablespace_databases and query their pg_class catalogs.
pg_tablespace_location ( tablespace oid ) → text Returns the file system path that this tablespace is located in.
pg_typeof ( "any" ) → regtype Returns the OID of the data type of the value that is passed to it. This can be helpful for troubleshooting or dynamically constructing SQL queries. The function is declared as returning regtype, which is an OID alias type (see Section 8.19); this means that it is the same as an OID for comparison purposes but displays as a type name. For example: SELECT pg_typeof(33); pg_typeof ----------- integer SELECT typlen FROM pg_type WHERE oid = pg_typeof(33); typlen -------- 4
COLLATION FOR ( "any" ) → text Returns the name of the collation of the value that is passed to it. The value is quoted and schema-qualified if necessary. If no collation was derived for the argument expression, then NULL is returned. If the argument is not of a collatable data type, then an error is raised. For example: SELECT collation for (description) FROM pg_description LIMIT 1; pg_collation_for ------------------ "default" SELECT collation for ('foo' COLLATE "de_DE"); pg_collation_for ------------------ "de_DE"
to_regclass ( text ) → regclass Translates a textual relation name to its OID. A similar result is obtained by casting the string to type regclass (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regcollation ( text ) → regcollation Translates a textual collation name to its OID. A similar result is obtained by casting the string to type regcollation (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regnamespace ( text ) → regnamespace Translates a textual schema name to its OID. A similar result is obtained by casting the string to type regnamespace (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regoper ( text ) → regoper Translates a textual operator name to its OID. A similar result is obtained by casting the string to type regoper (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found or is ambiguous. Also unlike the cast, this does not accept a numeric OID as input.
to_regoperator ( text ) → regoperator Translates a textual operator name (with parameter types) to its OID. A similar result is obtained by casting the string to type regoperator (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regproc ( text ) → regproc Translates a textual function or procedure name to its OID. A similar result is obtained by casting the string to type regproc (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found or is ambiguous. Also unlike the cast, this does not accept a numeric OID as input.
to_regprocedure ( text ) → regprocedure Translates a textual function or procedure name (with argument types) to its OID. A similar result is obtained by casting the string to type regprocedure (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regrole ( text ) → regrole Translates a textual role name to its OID. A similar result is obtained by casting the string to type regrole (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.
to_regtype ( text ) → regtype Translates a textual type name to its OID. A similar result is obtained by casting the string to type regtype (see Section 8.19); however, this function will return NULL rather than throwing an error if the name is not found. Also unlike the cast, this does not accept a numeric OID as input.