mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Standard pgindent run for 8.1.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.126 2005/10/04 19:01:18 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.127 2005/10/15 02:49:40 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "describe.h"
|
||||
@ -37,8 +37,8 @@ static void processNamePattern(PQExpBuffer buf, const char *pattern,
|
||||
const char *schemavar, const char *namevar,
|
||||
const char *altnamevar, const char *visibilityrule);
|
||||
|
||||
static bool add_tablespace_footer(char relkind, Oid tablespace, char **footers,
|
||||
int *count, PQExpBufferData buf, bool newline);
|
||||
static bool add_tablespace_footer(char relkind, Oid tablespace, char **footers,
|
||||
int *count, PQExpBufferData buf, bool newline);
|
||||
|
||||
/*----------------
|
||||
* Handlers for various slash commands displaying some sort of list
|
||||
@ -62,20 +62,20 @@ describeAggregates(const char *pattern, bool verbose)
|
||||
initPQExpBuffer(&buf);
|
||||
|
||||
/*
|
||||
* There are two kinds of aggregates: ones that work on particular
|
||||
* types and ones that work on all (denoted by input type = "any")
|
||||
* There are two kinds of aggregates: ones that work on particular types
|
||||
* and ones that work on all (denoted by input type = "any")
|
||||
*/
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT n.nspname as \"%s\",\n"
|
||||
" p.proname AS \"%s\",\n"
|
||||
" CASE p.proargtypes[0]\n"
|
||||
" WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n"
|
||||
" WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n"
|
||||
" THEN CAST('%s' AS pg_catalog.text)\n"
|
||||
" ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n"
|
||||
" ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n"
|
||||
" END AS \"%s\",\n"
|
||||
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
|
||||
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
|
||||
"FROM pg_catalog.pg_proc p\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
"WHERE p.proisagg\n",
|
||||
_("Schema"), _("Name"), _("(all types)"),
|
||||
_("Data type"), _("Description"));
|
||||
@ -121,7 +121,7 @@ describeTablespaces(const char *pattern, bool verbose)
|
||||
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT spcname AS \"%s\",\n"
|
||||
" pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
|
||||
" pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
|
||||
" spclocation AS \"%s\"",
|
||||
_("Name"), _("Owner"), _("Location"));
|
||||
|
||||
@ -170,9 +170,9 @@ describeFunctions(const char *pattern, bool verbose)
|
||||
"SELECT n.nspname as \"%s\",\n"
|
||||
" p.proname as \"%s\",\n"
|
||||
" CASE WHEN p.proretset THEN 'setof ' ELSE '' END ||\n"
|
||||
" pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
|
||||
" pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
|
||||
" pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"",
|
||||
_("Schema"), _("Name"), _("Result data type"),
|
||||
_("Schema"), _("Name"), _("Result data type"),
|
||||
_("Argument data types"));
|
||||
|
||||
if (verbose)
|
||||
@ -180,7 +180,7 @@ describeFunctions(const char *pattern, bool verbose)
|
||||
",\n r.rolname as \"%s\",\n"
|
||||
" l.lanname as \"%s\",\n"
|
||||
" p.prosrc as \"%s\",\n"
|
||||
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
|
||||
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
|
||||
_("Owner"), _("Language"),
|
||||
_("Source code"), _("Description"));
|
||||
|
||||
@ -191,16 +191,15 @@ describeFunctions(const char *pattern, bool verbose)
|
||||
else
|
||||
appendPQExpBuffer(&buf,
|
||||
"\nFROM pg_catalog.pg_proc p"
|
||||
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace"
|
||||
"\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang"
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON r.oid = p.proowner\n");
|
||||
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace"
|
||||
"\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang"
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON r.oid = p.proowner\n");
|
||||
|
||||
/*
|
||||
* we skip in/out funcs by excluding functions that take or return
|
||||
* cstring
|
||||
* we skip in/out funcs by excluding functions that take or return cstring
|
||||
*/
|
||||
appendPQExpBuffer(&buf,
|
||||
"WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
|
||||
"WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
|
||||
" AND (p.proargtypes[0] IS NULL\n"
|
||||
" OR p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype)\n"
|
||||
" AND NOT p.proisagg\n");
|
||||
@ -242,7 +241,7 @@ describeTypes(const char *pattern, bool verbose)
|
||||
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT n.nspname as \"%s\",\n"
|
||||
" pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
|
||||
" pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
|
||||
_("Schema"), _("Name"));
|
||||
if (verbose)
|
||||
appendPQExpBuffer(&buf,
|
||||
@ -255,16 +254,15 @@ describeTypes(const char *pattern, bool verbose)
|
||||
" END AS \"%s\",\n",
|
||||
_("Internal name"), _("Size"));
|
||||
appendPQExpBuffer(&buf,
|
||||
" pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
|
||||
" pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
|
||||
_("Description"));
|
||||
|
||||
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_type t\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
|
||||
|
||||
/*
|
||||
* do not include array types (start with underscore); do not include
|
||||
* complex types (typrelid!=0) unless they are standalone composite
|
||||
* types
|
||||
* complex types (typrelid!=0) unless they are standalone composite types
|
||||
*/
|
||||
appendPQExpBuffer(&buf, "WHERE (t.typrelid = 0 ");
|
||||
appendPQExpBuffer(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
|
||||
@ -311,11 +309,11 @@ describeOperators(const char *pattern)
|
||||
" o.oprname AS \"%s\",\n"
|
||||
" CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
|
||||
" CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
|
||||
" pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n"
|
||||
" coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
|
||||
" pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
|
||||
" pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n"
|
||||
" coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
|
||||
" pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
|
||||
"FROM pg_catalog.pg_operator o\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
|
||||
_("Schema"), _("Name"),
|
||||
_("Left arg type"), _("Right arg type"),
|
||||
_("Result type"), _("Description"));
|
||||
@ -360,7 +358,7 @@ listAllDbs(bool verbose)
|
||||
" r.rolname as \"%s\"",
|
||||
_("Name"), _("Owner"));
|
||||
appendPQExpBuffer(&buf,
|
||||
",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"",
|
||||
",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"",
|
||||
_("Encoding"));
|
||||
if (verbose)
|
||||
appendPQExpBuffer(&buf,
|
||||
@ -368,7 +366,7 @@ listAllDbs(bool verbose)
|
||||
_("Description"));
|
||||
appendPQExpBuffer(&buf,
|
||||
"\nFROM pg_catalog.pg_database d"
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON d.datdba = r.oid\n"
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON d.datdba = r.oid\n"
|
||||
"ORDER BY 1;");
|
||||
|
||||
res = PSQLexec(buf.data, false);
|
||||
@ -400,8 +398,7 @@ permissionsList(const char *pattern)
|
||||
initPQExpBuffer(&buf);
|
||||
|
||||
/*
|
||||
* we ignore indexes and toast tables since they have no meaningful
|
||||
* rights
|
||||
* we ignore indexes and toast tables since they have no meaningful rights
|
||||
*/
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT n.nspname as \"%s\",\n"
|
||||
@ -409,19 +406,19 @@ permissionsList(const char *pattern)
|
||||
" CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' END as \"%s\",\n"
|
||||
" c.relacl as \"%s\"\n"
|
||||
"FROM pg_catalog.pg_class c\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
"WHERE c.relkind IN ('r', 'v', 'S')\n",
|
||||
_("Schema"), _("Name"), _("table"), _("view"), _("sequence"), _("Type"), _("Access privileges"));
|
||||
|
||||
/*
|
||||
* Unless a schema pattern is specified, we suppress system and temp
|
||||
* tables, since they normally aren't very interesting from a
|
||||
* permissions point of view. You can see 'em by explicit request
|
||||
* though, eg with \z pg_catalog.*
|
||||
* tables, since they normally aren't very interesting from a permissions
|
||||
* point of view. You can see 'em by explicit request though, eg with \z
|
||||
* pg_catalog.*
|
||||
*/
|
||||
processNamePattern(&buf, pattern, true, false,
|
||||
"n.nspname", "c.relname", NULL,
|
||||
"n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
|
||||
"n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
|
||||
|
||||
appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
|
||||
|
||||
@ -465,7 +462,7 @@ objectDescription(const char *pattern)
|
||||
appendPQExpBuffer(&buf,
|
||||
"SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
|
||||
"FROM (\n",
|
||||
_("Schema"), _("Name"), _("Object"), _("Description"));
|
||||
_("Schema"), _("Name"), _("Object"), _("Description"));
|
||||
|
||||
/* Aggregate descriptions */
|
||||
appendPQExpBuffer(&buf,
|
||||
@ -474,7 +471,7 @@ objectDescription(const char *pattern)
|
||||
" CAST(p.proname AS pg_catalog.text) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_proc p\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
" WHERE p.proisagg\n",
|
||||
_("aggregate"));
|
||||
processNamePattern(&buf, pattern, true, false,
|
||||
@ -489,9 +486,9 @@ objectDescription(const char *pattern)
|
||||
" CAST(p.proname AS pg_catalog.text) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_proc p\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
|
||||
|
||||
" WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
|
||||
" WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
|
||||
" AND (p.proargtypes[0] IS NULL\n"
|
||||
" OR p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype)\n"
|
||||
" AND NOT p.proisagg\n",
|
||||
@ -508,7 +505,7 @@ objectDescription(const char *pattern)
|
||||
" CAST(o.oprname AS pg_catalog.text) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_operator o\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
|
||||
_("operator"));
|
||||
processNamePattern(&buf, pattern, false, false,
|
||||
"n.nspname", "o.oprname", NULL,
|
||||
@ -522,10 +519,10 @@ objectDescription(const char *pattern)
|
||||
" pg_catalog.format_type(t.oid, NULL) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_type t\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
|
||||
_("data type"));
|
||||
processNamePattern(&buf, pattern, false, false,
|
||||
"n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL,
|
||||
"n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL,
|
||||
"pg_catalog.pg_type_is_visible(t.oid)");
|
||||
|
||||
/* Relation (tables, views, indexes, sequences) descriptions */
|
||||
@ -538,7 +535,7 @@ objectDescription(const char *pattern)
|
||||
" CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' END"
|
||||
" AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_class c\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
" WHERE c.relkind IN ('r', 'v', 'i', 'S')\n",
|
||||
_("table"), _("view"), _("index"), _("sequence"));
|
||||
processNamePattern(&buf, pattern, true, false,
|
||||
@ -553,8 +550,8 @@ objectDescription(const char *pattern)
|
||||
" CAST(r.rulename AS pg_catalog.text) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_rewrite r\n"
|
||||
" JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
" JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
|
||||
" WHERE r.rulename != '_RETURN'\n",
|
||||
_("rule"));
|
||||
/* XXX not sure what to do about visibility rule here? */
|
||||
@ -570,8 +567,8 @@ objectDescription(const char *pattern)
|
||||
" CAST(t.tgname AS pg_catalog.text) as name,"
|
||||
" CAST('%s' AS pg_catalog.text) as object\n"
|
||||
" FROM pg_catalog.pg_trigger t\n"
|
||||
" JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
|
||||
" JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
|
||||
_("trigger"));
|
||||
/* XXX not sure what to do about visibility rule here? */
|
||||
processNamePattern(&buf, pattern, false, false,
|
||||
@ -622,7 +619,7 @@ describeTableDetails(const char *pattern, bool verbose)
|
||||
" n.nspname,\n"
|
||||
" c.relname\n"
|
||||
"FROM pg_catalog.pg_class c\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
|
||||
|
||||
processNamePattern(&buf, pattern, false, false,
|
||||
"n.nspname", "c.relname", NULL,
|
||||
@ -712,7 +709,7 @@ describeOneTableDetails(const char *schemaname,
|
||||
|
||||
/* Get general table info */
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
|
||||
"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
|
||||
"relhasoids %s \n"
|
||||
"FROM pg_catalog.pg_class WHERE oid = '%s'",
|
||||
pset.sversion >= 80000 ? ", reltablespace" : "",
|
||||
@ -886,7 +883,7 @@ describeOneTableDetails(const char *schemaname,
|
||||
break;
|
||||
default:
|
||||
printfPQExpBuffer(&title, _("?%c? \"%s.%s\""),
|
||||
tableinfo.relkind, schemaname, relationname);
|
||||
tableinfo.relkind, schemaname, relationname);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -898,9 +895,9 @@ describeOneTableDetails(const char *schemaname,
|
||||
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT i.indisunique, i.indisprimary, i.indisclustered, a.amname, c2.relname,\n"
|
||||
" pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
|
||||
" pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
|
||||
"FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
|
||||
"WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
|
||||
"WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
|
||||
"AND i.indrelid = c2.oid",
|
||||
oid);
|
||||
|
||||
@ -962,7 +959,7 @@ describeOneTableDetails(const char *schemaname,
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
|
||||
"FROM pg_catalog.pg_rewrite r\n"
|
||||
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1",
|
||||
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1",
|
||||
oid);
|
||||
result = PSQLexec(buf.data, false);
|
||||
if (!result)
|
||||
@ -1023,10 +1020,10 @@ describeOneTableDetails(const char *schemaname,
|
||||
{
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "
|
||||
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace\n"
|
||||
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace\n"
|
||||
"FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
|
||||
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
|
||||
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
|
||||
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
|
||||
oid);
|
||||
result1 = PSQLexec(buf.data, false);
|
||||
if (!result1)
|
||||
@ -1040,10 +1037,10 @@ describeOneTableDetails(const char *schemaname,
|
||||
{
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT "
|
||||
"pg_catalog.pg_get_constraintdef(r.oid, true), "
|
||||
"pg_catalog.pg_get_constraintdef(r.oid, true), "
|
||||
"conname\n"
|
||||
"FROM pg_catalog.pg_constraint r\n"
|
||||
"WHERE r.conrelid = '%s' AND r.contype = 'c' ORDER BY 1",
|
||||
"WHERE r.conrelid = '%s' AND r.contype = 'c' ORDER BY 1",
|
||||
oid);
|
||||
result2 = PSQLexec(buf.data, false);
|
||||
if (!result2)
|
||||
@ -1078,7 +1075,7 @@ describeOneTableDetails(const char *schemaname,
|
||||
if (tableinfo.triggers)
|
||||
{
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid)\n"
|
||||
"SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid)\n"
|
||||
"FROM pg_catalog.pg_trigger t\n"
|
||||
"WHERE t.tgrelid = '%s' "
|
||||
"AND (not tgisconstraint "
|
||||
@ -1105,9 +1102,9 @@ describeOneTableDetails(const char *schemaname,
|
||||
{
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT conname,\n"
|
||||
" pg_catalog.pg_get_constraintdef(oid, true) as condef\n"
|
||||
" pg_catalog.pg_get_constraintdef(oid, true) as condef\n"
|
||||
"FROM pg_catalog.pg_constraint r\n"
|
||||
"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
|
||||
"WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1",
|
||||
oid);
|
||||
result5 = PSQLexec(buf.data, false);
|
||||
if (!result5)
|
||||
@ -1143,7 +1140,7 @@ describeOneTableDetails(const char *schemaname,
|
||||
{
|
||||
const char *indexdef;
|
||||
const char *usingpos;
|
||||
PQExpBufferData tmpbuf;
|
||||
PQExpBufferData tmpbuf;
|
||||
|
||||
/* Output index name */
|
||||
printfPQExpBuffer(&buf, _(" \"%s\""),
|
||||
@ -1151,11 +1148,11 @@ describeOneTableDetails(const char *schemaname,
|
||||
|
||||
/* Label as primary key or unique (but not both) */
|
||||
appendPQExpBuffer(&buf,
|
||||
strcmp(PQgetvalue(result1, i, 1), "t") == 0
|
||||
strcmp(PQgetvalue(result1, i, 1), "t") == 0
|
||||
? " PRIMARY KEY," :
|
||||
(strcmp(PQgetvalue(result1, i, 2), "t") == 0
|
||||
? " UNIQUE,"
|
||||
: ""));
|
||||
(strcmp(PQgetvalue(result1, i, 2), "t") == 0
|
||||
? " UNIQUE,"
|
||||
: ""));
|
||||
/* Everything after "USING" is echoed verbatim */
|
||||
indexdef = PQgetvalue(result1, i, 4);
|
||||
usingpos = strstr(indexdef, " USING ");
|
||||
@ -1170,9 +1167,9 @@ describeOneTableDetails(const char *schemaname,
|
||||
/* Print tablespace of the index on the same line */
|
||||
count_footers += 1;
|
||||
initPQExpBuffer(&tmpbuf);
|
||||
if (add_tablespace_footer('i',
|
||||
atooid(PQgetvalue(result1, i, 5)),
|
||||
footers, &count_footers, tmpbuf, false))
|
||||
if (add_tablespace_footer('i',
|
||||
atooid(PQgetvalue(result1, i, 5)),
|
||||
footers, &count_footers, tmpbuf, false))
|
||||
{
|
||||
appendPQExpBuffer(&buf, ", ");
|
||||
appendPQExpBuffer(&buf, tmpbuf.data);
|
||||
@ -1335,9 +1332,9 @@ error_return:
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return true if the relation uses non default tablespace;
|
||||
* otherwise return false
|
||||
/*
|
||||
* Return true if the relation uses non default tablespace;
|
||||
* otherwise return false
|
||||
*/
|
||||
static bool
|
||||
add_tablespace_footer(char relkind, Oid tablespace, char **footers,
|
||||
@ -1347,8 +1344,8 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
|
||||
if (relkind == 'r' || relkind == 'i')
|
||||
{
|
||||
/*
|
||||
* We ignore the database default tablespace so that users not
|
||||
* using tablespaces don't need to know about them.
|
||||
* We ignore the database default tablespace so that users not using
|
||||
* tablespaces don't need to know about them.
|
||||
*/
|
||||
if (tablespace != 0)
|
||||
{
|
||||
@ -1362,9 +1359,9 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
|
||||
/* Should always be the case, but.... */
|
||||
if (PQntuples(result1) > 0)
|
||||
{
|
||||
printfPQExpBuffer(&buf,
|
||||
newline?_("Tablespace: \"%s\""):_("tablespace \"%s\""),
|
||||
PQgetvalue(result1, 0, 0));
|
||||
printfPQExpBuffer(&buf,
|
||||
newline ? _("Tablespace: \"%s\"") : _("tablespace \"%s\""),
|
||||
PQgetvalue(result1, 0, 0));
|
||||
|
||||
footers[(*count)++] = pg_strdup(buf.data);
|
||||
}
|
||||
@ -1393,19 +1390,19 @@ describeRoles(const char *pattern)
|
||||
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT r.rolname AS \"%s\",\n"
|
||||
" CASE WHEN r.rolsuper THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolcreaterole THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolcreatedb THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolconnlimit < 0 THEN CAST('%s' AS pg_catalog.text)\n"
|
||||
" CASE WHEN r.rolsuper THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolcreaterole THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolcreatedb THEN '%s' ELSE '%s' END AS \"%s\",\n"
|
||||
" CASE WHEN r.rolconnlimit < 0 THEN CAST('%s' AS pg_catalog.text)\n"
|
||||
" ELSE CAST(r.rolconnlimit AS pg_catalog.text)\n"
|
||||
" END AS \"%s\", \n"
|
||||
" ARRAY(SELECT b.rolname FROM pg_catalog.pg_auth_members m JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) as \"%s\"\n"
|
||||
"FROM pg_catalog.pg_roles r\n",
|
||||
_("Role name"),
|
||||
_("yes"),_("no"),_("Superuser"),
|
||||
_("yes"),_("no"),_("Create role"),
|
||||
_("yes"),_("no"),_("Create DB"),
|
||||
_("no limit"),_("Connections"),
|
||||
_("yes"), _("no"), _("Superuser"),
|
||||
_("yes"), _("no"), _("Create role"),
|
||||
_("yes"), _("no"), _("Create DB"),
|
||||
_("no limit"), _("Connections"),
|
||||
_("Member of"));
|
||||
|
||||
processNamePattern(&buf, pattern, false, false,
|
||||
@ -1475,17 +1472,17 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
|
||||
|
||||
if (verbose)
|
||||
appendPQExpBuffer(&buf,
|
||||
",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
|
||||
",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
|
||||
_("Description"));
|
||||
|
||||
appendPQExpBuffer(&buf,
|
||||
"\nFROM pg_catalog.pg_class c"
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON r.oid = c.relowner"
|
||||
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
|
||||
"\n LEFT JOIN pg_catalog.pg_roles r ON r.oid = c.relowner"
|
||||
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
|
||||
if (showIndexes)
|
||||
appendPQExpBuffer(&buf,
|
||||
"\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
|
||||
"\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
|
||||
"\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
|
||||
"\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
|
||||
|
||||
appendPQExpBuffer(&buf, "\nWHERE c.relkind IN (");
|
||||
if (showTables)
|
||||
@ -1503,9 +1500,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
|
||||
|
||||
/*
|
||||
* If showSystem is specified, show only system objects (those in
|
||||
* pg_catalog). Otherwise, suppress system objects, including those
|
||||
* in pg_catalog and pg_toast. (We don't want to hide temp tables
|
||||
* though.)
|
||||
* pg_catalog). Otherwise, suppress system objects, including those in
|
||||
* pg_catalog and pg_toast. (We don't want to hide temp tables though.)
|
||||
*/
|
||||
if (showSystem)
|
||||
appendPQExpBuffer(&buf, " AND n.nspname = 'pg_catalog'\n");
|
||||
@ -1560,16 +1556,16 @@ listDomains(const char *pattern)
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT n.nspname as \"%s\",\n"
|
||||
" t.typname as \"%s\",\n"
|
||||
" pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
|
||||
" pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
|
||||
" CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
|
||||
" WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
|
||||
" WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
|
||||
" WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
|
||||
" ELSE ''\n"
|
||||
" END as \"%s\",\n"
|
||||
" pg_catalog.pg_get_constraintdef(r.oid, true) as \"%s\"\n"
|
||||
" pg_catalog.pg_get_constraintdef(r.oid, true) as \"%s\"\n"
|
||||
"FROM pg_catalog.pg_type t\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_constraint r ON t.oid = r.contypid\n"
|
||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
|
||||
" LEFT JOIN pg_catalog.pg_constraint r ON t.oid = r.contypid\n"
|
||||
"WHERE t.typtype = 'd'\n",
|
||||
_("Schema"),
|
||||
_("Name"),
|
||||
@ -1614,11 +1610,11 @@ listConversions(const char *pattern)
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT n.nspname AS \"%s\",\n"
|
||||
" c.conname AS \"%s\",\n"
|
||||
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
|
||||
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
|
||||
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
|
||||
" pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
|
||||
" CASE WHEN c.condefault THEN '%s'\n"
|
||||
" ELSE '%s' END AS \"%s\"\n"
|
||||
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
|
||||
"FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
|
||||
"WHERE n.oid = c.connamespace\n",
|
||||
_("Schema"),
|
||||
_("Name"),
|
||||
@ -1663,8 +1659,8 @@ listCasts(const char *pattern)
|
||||
initPQExpBuffer(&buf);
|
||||
/* NEED LEFT JOIN FOR BINARY CASTS */
|
||||
printfPQExpBuffer(&buf,
|
||||
"SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
|
||||
" pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
|
||||
"SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
|
||||
" pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
|
||||
" CASE WHEN castfunc = 0 THEN '%s'\n"
|
||||
" ELSE p.proname\n"
|
||||
" END as \"%s\",\n"
|
||||
@ -1672,7 +1668,7 @@ listCasts(const char *pattern)
|
||||
" WHEN c.castcontext = 'a' THEN '%s'\n"
|
||||
" ELSE '%s'\n"
|
||||
" END as \"%s\"\n"
|
||||
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
|
||||
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
|
||||
" ON c.castfunc = p.oid\n"
|
||||
"ORDER BY 1, 2",
|
||||
_("Source type"),
|
||||
@ -1719,14 +1715,14 @@ listSchemas(const char *pattern, bool verbose)
|
||||
if (verbose)
|
||||
appendPQExpBuffer(&buf,
|
||||
",\n n.nspacl as \"%s\","
|
||||
" pg_catalog.obj_description(n.oid, 'pg_namespace') as \"%s\"",
|
||||
" pg_catalog.obj_description(n.oid, 'pg_namespace') as \"%s\"",
|
||||
_("Access privileges"), _("Description"));
|
||||
|
||||
appendPQExpBuffer(&buf,
|
||||
"\nFROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_roles r\n"
|
||||
"\nFROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_roles r\n"
|
||||
" ON n.nspowner=r.oid\n"
|
||||
"WHERE (n.nspname !~ '^pg_temp_' OR\n"
|
||||
" n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */
|
||||
" n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */
|
||||
|
||||
processNamePattern(&buf, pattern, true, false,
|
||||
NULL, "n.nspname", NULL,
|
||||
@ -1796,9 +1792,9 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
|
||||
initPQExpBuffer(&namebuf);
|
||||
|
||||
/*
|
||||
* Parse the pattern, converting quotes and lower-casing unquoted
|
||||
* letters; we assume this was NOT done by scan_option. Also, adjust
|
||||
* shell-style wildcard characters into regexp notation.
|
||||
* Parse the pattern, converting quotes and lower-casing unquoted letters;
|
||||
* we assume this was NOT done by scan_option. Also, adjust shell-style
|
||||
* wildcard characters into regexp notation.
|
||||
*/
|
||||
inquotes = false;
|
||||
cp = pattern;
|
||||
@ -1845,12 +1841,11 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
|
||||
/*
|
||||
* Ordinary data character, transfer to pattern
|
||||
*
|
||||
* Inside double quotes, or at all times if parsing an operator
|
||||
* name, quote regexp special characters with a backslash to
|
||||
* avoid regexp errors. Outside quotes, however, let them
|
||||
* pass through as-is; this lets knowledgeable users build
|
||||
* regexp expressions that are more powerful than shell-style
|
||||
* patterns.
|
||||
* Inside double quotes, or at all times if parsing an operator name,
|
||||
* quote regexp special characters with a backslash to avoid
|
||||
* regexp errors. Outside quotes, however, let them pass through
|
||||
* as-is; this lets knowledgeable users build regexp expressions
|
||||
* that are more powerful than shell-style patterns.
|
||||
*/
|
||||
if ((inquotes || force_escape) &&
|
||||
strchr("|*+?()[]{}.^$\\", *cp))
|
||||
|
Reference in New Issue
Block a user