1996-07-09 08:22:35 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- syscat.sql-
|
|
|
|
-- sample queries to the system catalogs
|
|
|
|
--
|
|
|
|
--
|
2022-01-08 01:04:57 +01:00
|
|
|
-- Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2001-06-13 21:31:56 +02:00
|
|
|
-- Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2010-09-20 22:08:53 +02:00
|
|
|
-- src/tutorial/syscat.source
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2003-10-26 05:51:51 +01:00
|
|
|
--
|
|
|
|
-- Sets the schema search path to pg_catalog first, so that we do not
|
|
|
|
-- need to qualify every system object
|
|
|
|
--
|
2013-01-19 23:20:32 +01:00
|
|
|
SET search_path TO pg_catalog;
|
|
|
|
|
|
|
|
-- The LIKE pattern language requires underscores to be escaped, so make
|
|
|
|
-- sure the backslashes are not misinterpreted.
|
|
|
|
SET standard_conforming_strings TO on;
|
2003-10-26 05:51:51 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2005-08-15 04:40:36 +02:00
|
|
|
-- lists the names of all database owners and the name of their database(s)
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2005-08-15 04:40:36 +02:00
|
|
|
SELECT rolname, datname
|
|
|
|
FROM pg_roles, pg_database
|
|
|
|
WHERE pg_roles.oid = datdba
|
|
|
|
ORDER BY rolname, datname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
--
|
|
|
|
-- lists all user-defined classes
|
|
|
|
--
|
2003-10-31 04:58:15 +01:00
|
|
|
SELECT n.nspname, c.relname
|
|
|
|
FROM pg_class c, pg_namespace n
|
|
|
|
WHERE c.relnamespace=n.oid
|
|
|
|
and c.relkind = 'r' -- not indices, views, etc
|
2013-01-19 23:20:32 +01:00
|
|
|
and n.nspname not like 'pg\_%' -- not catalogs
|
2003-10-31 04:58:15 +01:00
|
|
|
and n.nspname != 'information_schema' -- not information_schema
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, relname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
2003-05-28 18:04:02 +02:00
|
|
|
-- lists all simple indices (ie. those that are defined over one simple
|
|
|
|
-- column reference)
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2003-10-26 05:51:51 +01:00
|
|
|
SELECT n.nspname AS schema_name,
|
2010-11-23 21:27:50 +01:00
|
|
|
bc.relname AS class_name,
|
|
|
|
ic.relname AS index_name,
|
1996-07-09 08:22:35 +02:00
|
|
|
a.attname
|
2003-10-26 05:51:51 +01:00
|
|
|
FROM pg_namespace n,
|
|
|
|
pg_class bc, -- base class
|
1996-07-09 08:22:35 +02:00
|
|
|
pg_class ic, -- index class
|
|
|
|
pg_index i,
|
|
|
|
pg_attribute a -- att in base
|
2003-10-26 05:51:51 +01:00
|
|
|
WHERE bc.relnamespace = n.oid
|
|
|
|
and i.indrelid = bc.oid
|
1996-07-09 08:22:35 +02:00
|
|
|
and i.indexrelid = ic.oid
|
|
|
|
and i.indkey[0] = a.attnum
|
2003-05-28 18:04:02 +02:00
|
|
|
and i.indnatts = 1
|
1996-07-09 08:22:35 +02:00
|
|
|
and a.attrelid = bc.oid
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY schema_name, class_name, index_name, attname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- lists the user-defined attributes and their types for all user-defined
|
|
|
|
-- classes
|
|
|
|
--
|
2003-10-26 05:51:51 +01:00
|
|
|
SELECT n.nspname, c.relname, a.attname, format_type(t.oid, null) as typname
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_class c,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_attribute a, pg_type t
|
|
|
|
WHERE n.oid = c.relnamespace
|
|
|
|
and c.relkind = 'r' -- no indices
|
2013-01-19 23:20:32 +01:00
|
|
|
and n.nspname not like 'pg\_%' -- no catalogs
|
2003-10-26 05:51:51 +01:00
|
|
|
and n.nspname != 'information_schema' -- no information_schema
|
1996-07-09 08:22:35 +02:00
|
|
|
and a.attnum > 0 -- no system att's
|
2003-10-26 05:51:51 +01:00
|
|
|
and not a.attisdropped -- no dropped columns
|
1996-07-09 08:22:35 +02:00
|
|
|
and a.attrelid = c.oid
|
|
|
|
and a.atttypid = t.oid
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, relname, attname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
1998-03-20 05:12:25 +01:00
|
|
|
-- lists all user-defined base types (not including array types)
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2005-08-15 04:40:36 +02:00
|
|
|
SELECT n.nspname, r.rolname, format_type(t.oid, null) as typname
|
|
|
|
FROM pg_type t, pg_roles r, pg_namespace n
|
|
|
|
WHERE r.oid = t.typowner
|
2003-10-26 05:51:51 +01:00
|
|
|
and t.typnamespace = n.oid
|
2005-08-15 04:40:36 +02:00
|
|
|
and t.typrelid = 0 -- no complex types
|
|
|
|
and t.typelem = 0 -- no arrays
|
2013-01-19 23:20:32 +01:00
|
|
|
and n.nspname not like 'pg\_%' -- no built-in types
|
2003-10-26 05:51:51 +01:00
|
|
|
and n.nspname != 'information_schema' -- no information_schema
|
2005-08-15 04:40:36 +02:00
|
|
|
ORDER BY nspname, rolname, typname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing
many grammatical ambiguity problems. It doesn't seem worth the
pain to continue to support it, so remove it.
There are some follow-on improvements we can make in the grammar,
but this commit only removes the bare minimum number of productions,
plus assorted backend support code.
Note that pg_dump and psql continue to have full support, since
they may be used against older servers. However, pg_dump warns
about postfix operators. There is also a check in pg_upgrade.
Documentation-wise, I (tgl) largely removed the "left unary"
terminology in favor of saying "prefix operator", which is
a more standard and IMO less confusing term.
I included a catversion bump, although no initial catalog data
changes here, to mark the boundary at which oprkind = 'r'
stopped being valid in pg_operator.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 01:38:05 +02:00
|
|
|
-- lists all prefix operators
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing
many grammatical ambiguity problems. It doesn't seem worth the
pain to continue to support it, so remove it.
There are some follow-on improvements we can make in the grammar,
but this commit only removes the bare minimum number of productions,
plus assorted backend support code.
Note that pg_dump and psql continue to have full support, since
they may be used against older servers. However, pg_dump warns
about postfix operators. There is also a check in pg_upgrade.
Documentation-wise, I (tgl) largely removed the "left unary"
terminology in favor of saying "prefix operator", which is
a more standard and IMO less confusing term.
I included a catversion bump, although no initial catalog data
changes here, to mark the boundary at which oprkind = 'r'
stopped being valid in pg_operator.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 01:38:05 +02:00
|
|
|
SELECT n.nspname, o.oprname AS prefix_op,
|
2003-10-26 05:51:51 +01:00
|
|
|
format_type(right_type.oid, null) AS operand,
|
|
|
|
format_type(result.oid, null) AS return_type
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_operator o,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_type right_type, pg_type result
|
|
|
|
WHERE o.oprnamespace = n.oid
|
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing
many grammatical ambiguity problems. It doesn't seem worth the
pain to continue to support it, so remove it.
There are some follow-on improvements we can make in the grammar,
but this commit only removes the bare minimum number of productions,
plus assorted backend support code.
Note that pg_dump and psql continue to have full support, since
they may be used against older servers. However, pg_dump warns
about postfix operators. There is also a check in pg_upgrade.
Documentation-wise, I (tgl) largely removed the "left unary"
terminology in favor of saying "prefix operator", which is
a more standard and IMO less confusing term.
I included a catversion bump, although no initial catalog data
changes here, to mark the boundary at which oprkind = 'r'
stopped being valid in pg_operator.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 01:38:05 +02:00
|
|
|
and o.oprkind = 'l' -- prefix ("left unary")
|
1998-03-01 00:37:10 +01:00
|
|
|
and o.oprright = right_type.oid
|
1996-07-09 08:22:35 +02:00
|
|
|
and o.oprresult = result.oid
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, operand;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing
many grammatical ambiguity problems. It doesn't seem worth the
pain to continue to support it, so remove it.
There are some follow-on improvements we can make in the grammar,
but this commit only removes the bare minimum number of productions,
plus assorted backend support code.
Note that pg_dump and psql continue to have full support, since
they may be used against older servers. However, pg_dump warns
about postfix operators. There is also a check in pg_upgrade.
Documentation-wise, I (tgl) largely removed the "left unary"
terminology in favor of saying "prefix operator", which is
a more standard and IMO less confusing term.
I included a catversion bump, although no initial catalog data
changes here, to mark the boundary at which oprkind = 'r'
stopped being valid in pg_operator.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 01:38:05 +02:00
|
|
|
-- lists all infix operators
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2003-10-26 05:51:51 +01:00
|
|
|
SELECT n.nspname, o.oprname AS binary_op,
|
|
|
|
format_type(left_type.oid, null) AS left_opr,
|
|
|
|
format_type(right_type.oid, null) AS right_opr,
|
|
|
|
format_type(result.oid, null) AS return_type
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_operator o, pg_type left_type,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_type right_type, pg_type result
|
|
|
|
WHERE o.oprnamespace = n.oid
|
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing
many grammatical ambiguity problems. It doesn't seem worth the
pain to continue to support it, so remove it.
There are some follow-on improvements we can make in the grammar,
but this commit only removes the bare minimum number of productions,
plus assorted backend support code.
Note that pg_dump and psql continue to have full support, since
they may be used against older servers. However, pg_dump warns
about postfix operators. There is also a check in pg_upgrade.
Documentation-wise, I (tgl) largely removed the "left unary"
terminology in favor of saying "prefix operator", which is
a more standard and IMO less confusing term.
I included a catversion bump, although no initial catalog data
changes here, to mark the boundary at which oprkind = 'r'
stopped being valid in pg_operator.
Mark Dilger, based on work by myself and Robert Haas;
review by John Naylor
Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
2020-09-18 01:38:05 +02:00
|
|
|
and o.oprkind = 'b' -- infix ("binary")
|
1998-03-01 00:37:10 +01:00
|
|
|
and o.oprleft = left_type.oid
|
|
|
|
and o.oprright = right_type.oid
|
1996-07-09 08:22:35 +02:00
|
|
|
and o.oprresult = result.oid
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, left_opr, right_opr;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- lists the name, number of arguments and the return type of all user-defined
|
|
|
|
-- C functions
|
|
|
|
--
|
2003-10-26 05:51:51 +01:00
|
|
|
SELECT n.nspname, p.proname, p.pronargs, format_type(t.oid, null) as return_type
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_proc p,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_language l, pg_type t
|
|
|
|
WHERE p.pronamespace = n.oid
|
2013-01-19 23:20:32 +01:00
|
|
|
and n.nspname not like 'pg\_%' -- no catalogs
|
2003-10-26 05:51:51 +01:00
|
|
|
and n.nspname != 'information_schema' -- no information_schema
|
2010-11-23 21:27:50 +01:00
|
|
|
and p.prolang = l.oid
|
1996-07-09 08:22:35 +02:00
|
|
|
and p.prorettype = t.oid
|
|
|
|
and l.lanname = 'c'
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, proname, pronargs, return_type;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
--
|
|
|
|
-- lists all aggregate functions and the types to which they can be applied
|
|
|
|
--
|
2003-10-26 05:51:51 +01:00
|
|
|
SELECT n.nspname, p.proname, format_type(t.oid, null) as typname
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_aggregate a,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_proc p, pg_type t
|
|
|
|
WHERE p.pronamespace = n.oid
|
|
|
|
and a.aggfnoid = p.oid
|
2002-04-11 22:00:18 +02:00
|
|
|
and p.proargtypes[0] = t.oid
|
2003-10-26 05:51:51 +01:00
|
|
|
ORDER BY nspname, proname, typname;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
--
|
2006-12-23 01:43:13 +01:00
|
|
|
-- lists all the operator families that can be used with each access method
|
|
|
|
-- as well as the operators that can be used with the respective operator
|
|
|
|
-- families
|
1996-07-09 08:22:35 +02:00
|
|
|
--
|
2006-12-23 01:43:13 +01:00
|
|
|
SELECT am.amname, n.nspname, opf.opfname, opr.oprname
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_namespace n, pg_am am, pg_opfamily opf,
|
2003-10-26 05:51:51 +01:00
|
|
|
pg_amop amop, pg_operator opr
|
2006-12-23 01:43:13 +01:00
|
|
|
WHERE opf.opfnamespace = n.oid
|
|
|
|
and opf.opfmethod = am.oid
|
|
|
|
and amop.amopfamily = opf.oid
|
1996-07-09 08:22:35 +02:00
|
|
|
and amop.amopopr = opr.oid
|
2006-12-23 01:43:13 +01:00
|
|
|
ORDER BY nspname, amname, opfname, oprname;
|
2003-10-26 05:51:51 +01:00
|
|
|
|
|
|
|
--
|
2013-01-19 23:20:32 +01:00
|
|
|
-- Reset the search path and standard_conforming_strings to their defaults
|
2003-10-26 05:51:51 +01:00
|
|
|
--
|
2013-01-19 23:20:32 +01:00
|
|
|
RESET search_path;
|
|
|
|
RESET standard_conforming_strings;
|