2 * psql - the PostgreSQL interactive terminal
4 * Support for the various \d ("describe") commands. Note that the current
5 * expectation is that all functions in this file will succeed when working
6 * with servers of versions 7.4 and up. It's okay to omit irrelevant
7 * information for an old server, but not to fail outright.
9 * Copyright (c) 2000-2014, PostgreSQL Global Development Group
11 * src/bin/psql/describe.c
13 #include "postgres_fe.h"
17 #include "catalog/pg_default_acl.h"
21 #include "dumputils.h"
25 #include "variables.h"
28 static bool describeOneTableDetails(const char *schemaname,
29 const char *relationname,
32 static void add_tablespace_footer(printTableContent *const cont, char relkind,
33 Oid tablespace, const bool newline);
34 static void add_role_attribute(PQExpBuffer buf, const char *const str);
35 static bool listTSParsersVerbose(const char *pattern);
36 static bool describeOneTSParser(const char *oid, const char *nspname,
38 static bool listTSConfigsVerbose(const char *pattern);
39 static bool describeOneTSConfig(const char *oid, const char *nspname,
41 const char *pnspname, const char *prsname);
42 static void printACLColumn(PQExpBuffer buf, const char *colname);
43 static bool listOneExtensionContents(const char *extname, const char *oid);
47 * Handlers for various slash commands displaying some sort of list
48 * of things in the database.
50 * Note: try to format the queries to look nice in -E output.
56 * Takes an optional regexp to select particular aggregates
59 describeAggregates(const char *pattern, bool verbose, bool showSystem)
63 printQueryOpt myopt = pset.popt;
65 initPQExpBuffer(&buf);
67 printfPQExpBuffer(&buf,
68 "SELECT n.nspname as \"%s\",\n"
69 " p.proname AS \"%s\",\n"
70 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n",
71 gettext_noop("Schema"),
73 gettext_noop("Result data type"));
75 if (pset.sversion >= 80400)
76 appendPQExpBuffer(&buf,
77 " CASE WHEN p.pronargs = 0\n"
78 " THEN CAST('*' AS pg_catalog.text)\n"
79 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
81 gettext_noop("Argument data types"));
82 else if (pset.sversion >= 80200)
83 appendPQExpBuffer(&buf,
84 " CASE WHEN p.pronargs = 0\n"
85 " THEN CAST('*' AS pg_catalog.text)\n"
87 " pg_catalog.array_to_string(ARRAY(\n"
89 " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
91 " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
94 gettext_noop("Argument data types"));
96 appendPQExpBuffer(&buf,
97 " pg_catalog.format_type(p.proargtypes[0], NULL) AS \"%s\",\n",
98 gettext_noop("Argument data types"));
100 appendPQExpBuffer(&buf,
101 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
102 "FROM pg_catalog.pg_proc p\n"
103 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
104 "WHERE p.proisagg\n",
105 gettext_noop("Description"));
107 if (!showSystem && !pattern)
108 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
109 " AND n.nspname <> 'information_schema'\n");
111 processSQLNamePattern(pset.db, &buf, pattern, true, false,
112 "n.nspname", "p.proname", NULL,
113 "pg_catalog.pg_function_is_visible(p.oid)");
115 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
117 res = PSQLexec(buf.data, false);
118 termPQExpBuffer(&buf);
122 myopt.nullPrint = NULL;
123 myopt.title = _("List of aggregate functions");
124 myopt.translate_header = true;
126 printQuery(res, &myopt, pset.queryFout, pset.logfile);
133 * Takes an optional regexp to select particular tablespaces
136 describeTablespaces(const char *pattern, bool verbose)
140 printQueryOpt myopt = pset.popt;
142 if (pset.sversion < 80000)
144 psql_error("The server (version %d.%d) does not support tablespaces.\n",
145 pset.sversion / 10000, (pset.sversion / 100) % 100);
149 initPQExpBuffer(&buf);
151 if (pset.sversion >= 90200)
152 printfPQExpBuffer(&buf,
153 "SELECT spcname AS \"%s\",\n"
154 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
155 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
156 gettext_noop("Name"),
157 gettext_noop("Owner"),
158 gettext_noop("Location"));
160 printfPQExpBuffer(&buf,
161 "SELECT spcname AS \"%s\",\n"
162 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
163 " spclocation AS \"%s\"",
164 gettext_noop("Name"),
165 gettext_noop("Owner"),
166 gettext_noop("Location"));
170 appendPQExpBufferStr(&buf, ",\n ");
171 printACLColumn(&buf, "spcacl");
174 if (verbose && pset.sversion >= 90000)
175 appendPQExpBuffer(&buf,
176 ",\n spcoptions AS \"%s\"",
177 gettext_noop("Options"));
179 if (verbose && pset.sversion >= 90200)
180 appendPQExpBuffer(&buf,
181 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"",
182 gettext_noop("Size"));
184 if (verbose && pset.sversion >= 80200)
185 appendPQExpBuffer(&buf,
186 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
187 gettext_noop("Description"));
189 appendPQExpBufferStr(&buf,
190 "\nFROM pg_catalog.pg_tablespace\n");
192 processSQLNamePattern(pset.db, &buf, pattern, false, false,
193 NULL, "spcname", NULL,
196 appendPQExpBufferStr(&buf, "ORDER BY 1;");
198 res = PSQLexec(buf.data, false);
199 termPQExpBuffer(&buf);
203 myopt.nullPrint = NULL;
204 myopt.title = _("List of tablespaces");
205 myopt.translate_header = true;
207 printQuery(res, &myopt, pset.queryFout, pset.logfile);
215 * Takes an optional regexp to select particular functions.
217 * As with \d, you can specify the kinds of functions you want:
224 * and you can mix and match these in any order.
227 describeFunctions(const char *functypes, const char *pattern, bool verbose, bool showSystem)
229 bool showAggregate = strchr(functypes, 'a') != NULL;
230 bool showNormal = strchr(functypes, 'n') != NULL;
231 bool showTrigger = strchr(functypes, 't') != NULL;
232 bool showWindow = strchr(functypes, 'w') != NULL;
236 printQueryOpt myopt = pset.popt;
237 static const bool translate_columns[] = {false, false, false, false, true, true, true, false, false, false, false};
239 if (strlen(functypes) != strspn(functypes, "antwS+"))
241 psql_error("\\df only takes [antwS+] as options\n");
245 if (showWindow && pset.sversion < 80400)
247 psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
248 pset.sversion / 10000, (pset.sversion / 100) % 100);
252 if (!showAggregate && !showNormal && !showTrigger && !showWindow)
254 showAggregate = showNormal = showTrigger = true;
255 if (pset.sversion >= 80400)
259 initPQExpBuffer(&buf);
261 printfPQExpBuffer(&buf,
262 "SELECT n.nspname as \"%s\",\n"
263 " p.proname as \"%s\",\n",
264 gettext_noop("Schema"),
265 gettext_noop("Name"));
267 if (pset.sversion >= 80400)
268 appendPQExpBuffer(&buf,
269 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
270 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
272 " WHEN p.proisagg THEN '%s'\n"
273 " WHEN p.proiswindow THEN '%s'\n"
274 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
277 gettext_noop("Result data type"),
278 gettext_noop("Argument data types"),
279 /* translator: "agg" is short for "aggregate" */
281 gettext_noop("window"),
282 gettext_noop("trigger"),
283 gettext_noop("normal"),
284 gettext_noop("Type"));
285 else if (pset.sversion >= 80100)
286 appendPQExpBuffer(&buf,
287 " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
288 " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
289 " CASE WHEN proallargtypes IS NOT NULL THEN\n"
290 " pg_catalog.array_to_string(ARRAY(\n"
293 " WHEN p.proargmodes[s.i] = 'i' THEN ''\n"
294 " WHEN p.proargmodes[s.i] = 'o' THEN 'OUT '\n"
295 " WHEN p.proargmodes[s.i] = 'b' THEN 'INOUT '\n"
296 " WHEN p.proargmodes[s.i] = 'v' THEN 'VARIADIC '\n"
299 " WHEN COALESCE(p.proargnames[s.i], '') = '' THEN ''\n"
300 " ELSE p.proargnames[s.i] || ' ' \n"
302 " pg_catalog.format_type(p.proallargtypes[s.i], NULL)\n"
304 " pg_catalog.generate_series(1, pg_catalog.array_upper(p.proallargtypes, 1)) AS s(i)\n"
307 " pg_catalog.array_to_string(ARRAY(\n"
310 " WHEN COALESCE(p.proargnames[s.i+1], '') = '' THEN ''\n"
311 " ELSE p.proargnames[s.i+1] || ' '\n"
313 " pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
315 " pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
319 " WHEN p.proisagg THEN '%s'\n"
320 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
323 gettext_noop("Result data type"),
324 gettext_noop("Argument data types"),
325 /* translator: "agg" is short for "aggregate" */
327 gettext_noop("trigger"),
328 gettext_noop("normal"),
329 gettext_noop("Type"));
331 appendPQExpBuffer(&buf,
332 " CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
333 " pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
334 " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
336 " WHEN p.proisagg THEN '%s'\n"
337 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
340 gettext_noop("Result data type"),
341 gettext_noop("Argument data types"),
342 /* translator: "agg" is short for "aggregate" */
344 gettext_noop("trigger"),
345 gettext_noop("normal"),
346 gettext_noop("Type"));
349 appendPQExpBuffer(&buf,
350 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
352 " WHEN p.provolatile = 'i' THEN '%s'\n"
353 " WHEN p.provolatile = 's' THEN '%s'\n"
354 " WHEN p.provolatile = 'v' THEN '%s'\n"
356 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\",\n"
357 " l.lanname as \"%s\",\n"
358 " p.prosrc as \"%s\",\n"
359 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
360 gettext_noop("definer"),
361 gettext_noop("invoker"),
362 gettext_noop("Security"),
363 gettext_noop("immutable"),
364 gettext_noop("stable"),
365 gettext_noop("volatile"),
366 gettext_noop("Volatility"),
367 gettext_noop("Owner"),
368 gettext_noop("Language"),
369 gettext_noop("Source code"),
370 gettext_noop("Description"));
372 appendPQExpBufferStr(&buf,
373 "\nFROM pg_catalog.pg_proc p"
374 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
377 appendPQExpBufferStr(&buf,
378 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
382 /* filter by function type, if requested */
383 if (showNormal && showAggregate && showTrigger && showWindow)
390 appendPQExpBufferStr(&buf, " AND ");
393 appendPQExpBufferStr(&buf, "WHERE ");
396 appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
401 appendPQExpBufferStr(&buf, " AND ");
404 appendPQExpBufferStr(&buf, "WHERE ");
407 appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
409 if (!showWindow && pset.sversion >= 80400)
412 appendPQExpBufferStr(&buf, " AND ");
415 appendPQExpBufferStr(&buf, "WHERE ");
418 appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
423 bool needs_or = false;
425 appendPQExpBufferStr(&buf, "WHERE (\n ");
427 /* Note: at least one of these must be true ... */
430 appendPQExpBufferStr(&buf, "p.proisagg\n");
436 appendPQExpBufferStr(&buf, " OR ");
437 appendPQExpBufferStr(&buf,
438 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
444 appendPQExpBufferStr(&buf, " OR ");
445 appendPQExpBufferStr(&buf, "p.proiswindow\n");
448 appendPQExpBufferStr(&buf, " )\n");
451 processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
452 "n.nspname", "p.proname", NULL,
453 "pg_catalog.pg_function_is_visible(p.oid)");
455 if (!showSystem && !pattern)
456 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
457 " AND n.nspname <> 'information_schema'\n");
459 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
461 res = PSQLexec(buf.data, false);
462 termPQExpBuffer(&buf);
466 myopt.nullPrint = NULL;
467 myopt.title = _("List of functions");
468 myopt.translate_header = true;
469 myopt.translate_columns = translate_columns;
470 myopt.n_translate_columns = lengthof(translate_columns);
472 printQuery(res, &myopt, pset.queryFout, pset.logfile);
485 describeTypes(const char *pattern, bool verbose, bool showSystem)
489 printQueryOpt myopt = pset.popt;
491 initPQExpBuffer(&buf);
493 printfPQExpBuffer(&buf,
494 "SELECT n.nspname as \"%s\",\n"
495 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
496 gettext_noop("Schema"),
497 gettext_noop("Name"));
499 appendPQExpBuffer(&buf,
500 " t.typname AS \"%s\",\n"
501 " CASE WHEN t.typrelid != 0\n"
502 " THEN CAST('tuple' AS pg_catalog.text)\n"
503 " WHEN t.typlen < 0\n"
504 " THEN CAST('var' AS pg_catalog.text)\n"
505 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
507 gettext_noop("Internal name"),
508 gettext_noop("Size"));
509 if (verbose && pset.sversion >= 80300)
511 appendPQExpBufferStr(&buf,
512 " pg_catalog.array_to_string(\n"
514 " SELECT e.enumlabel\n"
515 " FROM pg_catalog.pg_enum e\n"
516 " WHERE e.enumtypid = t.oid\n");
518 if (pset.sversion >= 90100)
519 appendPQExpBufferStr(&buf,
520 " ORDER BY e.enumsortorder\n");
522 appendPQExpBufferStr(&buf,
523 " ORDER BY e.oid\n");
525 appendPQExpBuffer(&buf,
529 gettext_noop("Elements"));
531 if (verbose && pset.sversion >= 90200)
533 printACLColumn(&buf, "t.typacl");
534 appendPQExpBufferStr(&buf, ",\n ");
537 appendPQExpBuffer(&buf,
538 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
539 gettext_noop("Description"));
541 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
542 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
545 * do not include complex types (typrelid!=0) unless they are standalone
548 appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
549 appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
550 "WHERE c.oid = t.typrelid))\n");
553 * do not include array types (before 8.3 we have to use the assumption
554 * that their names start with underscore)
556 if (pset.sversion >= 80300)
557 appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
559 appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
561 if (!showSystem && !pattern)
562 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
563 " AND n.nspname <> 'information_schema'\n");
565 /* Match name pattern against either internal or external name */
566 processSQLNamePattern(pset.db, &buf, pattern, true, false,
567 "n.nspname", "t.typname",
568 "pg_catalog.format_type(t.oid, NULL)",
569 "pg_catalog.pg_type_is_visible(t.oid)");
571 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
573 res = PSQLexec(buf.data, false);
574 termPQExpBuffer(&buf);
578 myopt.nullPrint = NULL;
579 myopt.title = _("List of data types");
580 myopt.translate_header = true;
582 printQuery(res, &myopt, pset.queryFout, pset.logfile);
593 describeOperators(const char *pattern, bool verbose, bool showSystem)
597 printQueryOpt myopt = pset.popt;
599 initPQExpBuffer(&buf);
602 * Note: before Postgres 9.1, we did not assign comments to any built-in
603 * operators, preferring to let the comment on the underlying function
604 * suffice. The coalesce() on the obj_description() calls below supports
605 * this convention by providing a fallback lookup of a comment on the
606 * operator's function. As of 9.1 there is a policy that every built-in
607 * operator should have a comment; so the coalesce() is no longer
608 * necessary so far as built-in operators are concerned. We keep it
609 * anyway, for now, because (1) third-party modules may still be following
610 * the old convention, and (2) we'd need to do it anyway when talking to a
614 printfPQExpBuffer(&buf,
615 "SELECT n.nspname as \"%s\",\n"
616 " o.oprname AS \"%s\",\n"
617 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
618 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
619 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
620 gettext_noop("Schema"),
621 gettext_noop("Name"),
622 gettext_noop("Left arg type"),
623 gettext_noop("Right arg type"),
624 gettext_noop("Result type"));
627 appendPQExpBuffer(&buf,
628 " o.oprcode AS \"%s\",\n",
629 gettext_noop("Function"));
631 appendPQExpBuffer(&buf,
632 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
633 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
634 "FROM pg_catalog.pg_operator o\n"
635 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
636 gettext_noop("Description"));
638 if (!showSystem && !pattern)
639 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
640 " AND n.nspname <> 'information_schema'\n");
642 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
643 "n.nspname", "o.oprname", NULL,
644 "pg_catalog.pg_operator_is_visible(o.oid)");
646 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
648 res = PSQLexec(buf.data, false);
649 termPQExpBuffer(&buf);
653 myopt.nullPrint = NULL;
654 myopt.title = _("List of operators");
655 myopt.translate_header = true;
657 printQuery(res, &myopt, pset.queryFout, pset.logfile);
667 * for \l, \list, and -l switch
670 listAllDbs(const char *pattern, bool verbose)
674 printQueryOpt myopt = pset.popt;
676 initPQExpBuffer(&buf);
678 printfPQExpBuffer(&buf,
679 "SELECT d.datname as \"%s\",\n"
680 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
681 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
682 gettext_noop("Name"),
683 gettext_noop("Owner"),
684 gettext_noop("Encoding"));
685 if (pset.sversion >= 80400)
686 appendPQExpBuffer(&buf,
687 " d.datcollate as \"%s\",\n"
688 " d.datctype as \"%s\",\n",
689 gettext_noop("Collate"),
690 gettext_noop("Ctype"));
691 appendPQExpBufferStr(&buf, " ");
692 printACLColumn(&buf, "d.datacl");
693 if (verbose && pset.sversion >= 80200)
694 appendPQExpBuffer(&buf,
695 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
696 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
697 " ELSE 'No Access'\n"
699 gettext_noop("Size"));
700 if (verbose && pset.sversion >= 80000)
701 appendPQExpBuffer(&buf,
702 ",\n t.spcname as \"%s\"",
703 gettext_noop("Tablespace"));
704 if (verbose && pset.sversion >= 80200)
705 appendPQExpBuffer(&buf,
706 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
707 gettext_noop("Description"));
708 appendPQExpBufferStr(&buf,
709 "\nFROM pg_catalog.pg_database d\n");
710 if (verbose && pset.sversion >= 80000)
711 appendPQExpBufferStr(&buf,
712 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
715 processSQLNamePattern(pset.db, &buf, pattern, false, false,
716 NULL, "d.datname", NULL, NULL);
718 appendPQExpBufferStr(&buf, "ORDER BY 1;");
719 res = PSQLexec(buf.data, false);
720 termPQExpBuffer(&buf);
724 myopt.nullPrint = NULL;
725 myopt.title = _("List of databases");
726 myopt.translate_header = true;
728 printQuery(res, &myopt, pset.queryFout, pset.logfile);
736 * List Tables' Grant/Revoke Permissions
737 * \z (now also \dp -- perhaps more mnemonic)
740 permissionsList(const char *pattern)
744 printQueryOpt myopt = pset.popt;
745 static const bool translate_columns[] = {false, false, true, false, false, false};
747 initPQExpBuffer(&buf);
750 * we ignore indexes and toast tables since they have no meaningful rights
752 printfPQExpBuffer(&buf,
753 "SELECT n.nspname as \"%s\",\n"
754 " c.relname as \"%s\",\n"
756 " WHEN 'r' THEN '%s'"
757 " WHEN 'v' THEN '%s'"
758 " WHEN 'm' THEN '%s'"
759 " WHEN 'S' THEN '%s'"
760 " WHEN 'f' THEN '%s'"
763 gettext_noop("Schema"),
764 gettext_noop("Name"),
765 gettext_noop("table"),
766 gettext_noop("view"),
767 gettext_noop("materialized view"),
768 gettext_noop("sequence"),
769 gettext_noop("foreign table"),
770 gettext_noop("Type"));
772 printACLColumn(&buf, "c.relacl");
774 if (pset.sversion >= 80400)
775 appendPQExpBuffer(&buf,
776 ",\n pg_catalog.array_to_string(ARRAY(\n"
777 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
778 " FROM pg_catalog.pg_attribute a\n"
779 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
780 " ), E'\\n') AS \"%s\"",
781 gettext_noop("Column privileges"));
783 if (pset.sversion >= 90500)
784 appendPQExpBuffer(&buf,
785 ",\n pg_catalog.array_to_string(ARRAY(\n"
786 " SELECT rsecpolname\n"
787 " || CASE WHEN rseccmd IS NOT NULL THEN\n"
788 " E' (' || rseccmd || E')'\n"
791 " || CASE WHEN rs.rsecqual IS NOT NULL THEN\n"
792 " E'\\n (u): ' || pg_catalog.pg_get_expr(rsecqual, rsecrelid)\n"
795 " || CASE WHEN rsecwithcheck IS NOT NULL THEN\n"
796 " E'\\n (c): ' || pg_catalog.pg_get_expr(rsecwithcheck, rsecrelid)\n"
799 " || CASE WHEN rs.rsecroles <> '{0}' THEN\n"
800 " E'\\n to: ' || pg_catalog.array_to_string(\n"
803 " FROM pg_catalog.pg_roles\n"
804 " WHERE oid = ANY (rs.rsecroles)\n"
809 " FROM pg_catalog.pg_rowsecurity rs\n"
810 " WHERE rsecrelid = c.oid), E'\\n')\n"
812 gettext_noop("Policies"));
814 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
815 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
816 "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')\n");
819 * Unless a schema pattern is specified, we suppress system and temp
820 * tables, since they normally aren't very interesting from a permissions
821 * point of view. You can see 'em by explicit request though, eg with \z
824 processSQLNamePattern(pset.db, &buf, pattern, true, false,
825 "n.nspname", "c.relname", NULL,
826 "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
828 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
830 res = PSQLexec(buf.data, false);
833 termPQExpBuffer(&buf);
837 myopt.nullPrint = NULL;
838 printfPQExpBuffer(&buf, _("Access privileges"));
839 myopt.title = buf.data;
840 myopt.translate_header = true;
841 myopt.translate_columns = translate_columns;
842 myopt.n_translate_columns = lengthof(translate_columns);
844 printQuery(res, &myopt, pset.queryFout, pset.logfile);
846 termPQExpBuffer(&buf);
855 * List Default ACLs. The pattern can match either schema or role name.
858 listDefaultACLs(const char *pattern)
862 printQueryOpt myopt = pset.popt;
863 static const bool translate_columns[] = {false, false, true, false};
865 if (pset.sversion < 90000)
867 psql_error("The server (version %d.%d) does not support altering default privileges.\n",
868 pset.sversion / 10000, (pset.sversion / 100) % 100);
872 initPQExpBuffer(&buf);
874 printfPQExpBuffer(&buf,
875 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
876 " n.nspname AS \"%s\",\n"
877 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
879 gettext_noop("Owner"),
880 gettext_noop("Schema"),
882 gettext_noop("table"),
884 gettext_noop("sequence"),
886 gettext_noop("function"),
888 gettext_noop("type"),
889 gettext_noop("Type"));
891 printACLColumn(&buf, "d.defaclacl");
893 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
894 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
896 processSQLNamePattern(pset.db, &buf, pattern, false, false,
899 "pg_catalog.pg_get_userbyid(d.defaclrole)",
902 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
904 res = PSQLexec(buf.data, false);
907 termPQExpBuffer(&buf);
911 myopt.nullPrint = NULL;
912 printfPQExpBuffer(&buf, _("Default access privileges"));
913 myopt.title = buf.data;
914 myopt.translate_header = true;
915 myopt.translate_columns = translate_columns;
916 myopt.n_translate_columns = lengthof(translate_columns);
918 printQuery(res, &myopt, pset.queryFout, pset.logfile);
920 termPQExpBuffer(&buf);
927 * Get object comments
931 * Note: This command only lists comments for object types which do not have
932 * their comments displayed by their own backslash commands. The following
933 * types of objects will be displayed: constraint, operator class,
934 * operator family, rule, and trigger.
938 objectDescription(const char *pattern, bool showSystem)
942 printQueryOpt myopt = pset.popt;
943 static const bool translate_columns[] = {false, false, true, false};
945 initPQExpBuffer(&buf);
947 appendPQExpBuffer(&buf,
948 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
950 gettext_noop("Schema"),
951 gettext_noop("Name"),
952 gettext_noop("Object"),
953 gettext_noop("Description"));
955 /* Constraint descriptions */
956 appendPQExpBuffer(&buf,
957 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
958 " n.nspname as nspname,\n"
959 " CAST(pgc.conname AS pg_catalog.text) as name,"
960 " CAST('%s' AS pg_catalog.text) as object\n"
961 " FROM pg_catalog.pg_constraint pgc\n"
962 " JOIN pg_catalog.pg_class c "
963 "ON c.oid = pgc.conrelid\n"
964 " LEFT JOIN pg_catalog.pg_namespace n "
965 " ON n.oid = c.relnamespace\n",
966 gettext_noop("constraint"));
968 if (!showSystem && !pattern)
969 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
970 " AND n.nspname <> 'information_schema'\n");
972 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
973 false, "n.nspname", "pgc.conname", NULL,
974 "pg_catalog.pg_table_is_visible(c.oid)");
977 * pg_opclass.opcmethod only available in 8.3+
979 if (pset.sversion >= 80300)
981 /* Operator class descriptions */
982 appendPQExpBuffer(&buf,
984 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
985 " n.nspname as nspname,\n"
986 " CAST(o.opcname AS pg_catalog.text) as name,\n"
987 " CAST('%s' AS pg_catalog.text) as object\n"
988 " FROM pg_catalog.pg_opclass o\n"
989 " JOIN pg_catalog.pg_am am ON "
990 "o.opcmethod = am.oid\n"
991 " JOIN pg_catalog.pg_namespace n ON "
992 "n.oid = o.opcnamespace\n",
993 gettext_noop("operator class"));
995 if (!showSystem && !pattern)
996 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
997 " AND n.nspname <> 'information_schema'\n");
999 processSQLNamePattern(pset.db, &buf, pattern, true, false,
1000 "n.nspname", "o.opcname", NULL,
1001 "pg_catalog.pg_opclass_is_visible(o.oid)");
1005 * although operator family comments have been around since 8.3,
1006 * pg_opfamily_is_visible is only available in 9.2+
1008 if (pset.sversion >= 90200)
1010 /* Operator family descriptions */
1011 appendPQExpBuffer(&buf,
1013 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1014 " n.nspname as nspname,\n"
1015 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1016 " CAST('%s' AS pg_catalog.text) as object\n"
1017 " FROM pg_catalog.pg_opfamily opf\n"
1018 " JOIN pg_catalog.pg_am am "
1019 "ON opf.opfmethod = am.oid\n"
1020 " JOIN pg_catalog.pg_namespace n "
1021 "ON opf.opfnamespace = n.oid\n",
1022 gettext_noop("operator family"));
1024 if (!showSystem && !pattern)
1025 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1026 " AND n.nspname <> 'information_schema'\n");
1028 processSQLNamePattern(pset.db, &buf, pattern, true, false,
1029 "n.nspname", "opf.opfname", NULL,
1030 "pg_catalog.pg_opfamily_is_visible(opf.oid)");
1033 /* Rule descriptions (ignore rules for views) */
1034 appendPQExpBuffer(&buf,
1036 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1037 " n.nspname as nspname,\n"
1038 " CAST(r.rulename AS pg_catalog.text) as name,"
1039 " CAST('%s' AS pg_catalog.text) as object\n"
1040 " FROM pg_catalog.pg_rewrite r\n"
1041 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1042 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1043 " WHERE r.rulename != '_RETURN'\n",
1044 gettext_noop("rule"));
1046 if (!showSystem && !pattern)
1047 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
1048 " AND n.nspname <> 'information_schema'\n");
1050 processSQLNamePattern(pset.db, &buf, pattern, true, false,
1051 "n.nspname", "r.rulename", NULL,
1052 "pg_catalog.pg_table_is_visible(c.oid)");
1054 /* Trigger descriptions */
1055 appendPQExpBuffer(&buf,
1057 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1058 " n.nspname as nspname,\n"
1059 " CAST(t.tgname AS pg_catalog.text) as name,"
1060 " CAST('%s' AS pg_catalog.text) as object\n"
1061 " FROM pg_catalog.pg_trigger t\n"
1062 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1063 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1064 gettext_noop("trigger"));
1066 if (!showSystem && !pattern)
1067 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1068 " AND n.nspname <> 'information_schema'\n");
1070 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1071 "n.nspname", "t.tgname", NULL,
1072 "pg_catalog.pg_table_is_visible(c.oid)");
1074 appendPQExpBufferStr(&buf,
1076 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1078 appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
1080 res = PSQLexec(buf.data, false);
1081 termPQExpBuffer(&buf);
1085 myopt.nullPrint = NULL;
1086 myopt.title = _("Object descriptions");
1087 myopt.translate_header = true;
1088 myopt.translate_columns = translate_columns;
1089 myopt.n_translate_columns = lengthof(translate_columns);
1091 printQuery(res, &myopt, pset.queryFout, pset.logfile);
1099 * describeTableDetails (for \d)
1101 * This routine finds the tables to be displayed, and calls
1102 * describeOneTableDetails for each one.
1104 * verbose: if true, this is \d+
1107 describeTableDetails(const char *pattern, bool verbose, bool showSystem)
1109 PQExpBufferData buf;
1113 initPQExpBuffer(&buf);
1115 printfPQExpBuffer(&buf,
1119 "FROM pg_catalog.pg_class c\n"
1120 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1122 if (!showSystem && !pattern)
1123 appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
1124 " AND n.nspname <> 'information_schema'\n");
1126 processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
1127 "n.nspname", "c.relname", NULL,
1128 "pg_catalog.pg_table_is_visible(c.oid)");
1130 appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
1132 res = PSQLexec(buf.data, false);
1133 termPQExpBuffer(&buf);
1137 if (PQntuples(res) == 0)
1140 psql_error("Did not find any relation named \"%s\".\n",
1146 for (i = 0; i < PQntuples(res); i++)
1149 const char *nspname;
1150 const char *relname;
1152 oid = PQgetvalue(res, i, 0);
1153 nspname = PQgetvalue(res, i, 1);
1154 relname = PQgetvalue(res, i, 2);
1156 if (!describeOneTableDetails(nspname, relname, oid, verbose))
1173 * describeOneTableDetails (for \d)
1175 * Unfortunately, the information presented here is so complicated that it
1176 * cannot be done in a single query. So we have to assemble the printed table
1177 * by hand and pass it to the underlying printTable() function.
1180 describeOneTableDetails(const char *schemaname,
1181 const char *relationname,
1185 PQExpBufferData buf;
1186 PGresult *res = NULL;
1187 printTableOpt myopt = pset.popt.topt;
1188 printTableContent cont;
1189 bool printTableInitialized = false;
1191 char *view_def = NULL;
1193 char **seq_values = NULL;
1194 char **modifiers = NULL;
1196 PQExpBufferData title;
1197 PQExpBufferData tmpbuf;
1212 char relpersistence;
1215 bool show_modifiers = false;
1220 myopt.default_footer = false;
1221 /* This output looks confusing in expanded mode. */
1222 myopt.expanded = false;
1224 initPQExpBuffer(&buf);
1225 initPQExpBuffer(&title);
1226 initPQExpBuffer(&tmpbuf);
1228 /* Get general table info */
1229 if (pset.sversion >= 90500)
1231 printfPQExpBuffer(&buf,
1232 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1233 "c.relhastriggers, c.relrowsecurity, c.relhasoids, "
1234 "%s, c.reltablespace, "
1235 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1236 "c.relpersistence, c.relreplident\n"
1237 "FROM pg_catalog.pg_class c\n "
1238 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1239 "WHERE c.oid = '%s';",
1241 "pg_catalog.array_to_string(c.reloptions || "
1242 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1246 else if (pset.sversion >= 90400)
1248 printfPQExpBuffer(&buf,
1249 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1250 "c.relhastriggers, false, c.relhasoids, "
1251 "%s, c.reltablespace, "
1252 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1253 "c.relpersistence, c.relreplident\n"
1254 "FROM pg_catalog.pg_class c\n "
1255 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1256 "WHERE c.oid = '%s';",
1258 "pg_catalog.array_to_string(c.reloptions || "
1259 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1263 else if (pset.sversion >= 90100)
1265 printfPQExpBuffer(&buf,
1266 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1267 "c.relhastriggers, false, c.relhasoids, "
1268 "%s, c.reltablespace, "
1269 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1270 "c.relpersistence\n"
1271 "FROM pg_catalog.pg_class c\n "
1272 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1273 "WHERE c.oid = '%s';",
1275 "pg_catalog.array_to_string(c.reloptions || "
1276 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1280 else if (pset.sversion >= 90000)
1282 printfPQExpBuffer(&buf,
1283 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1284 "c.relhastriggers, false, c.relhasoids, "
1285 "%s, c.reltablespace, "
1286 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END\n"
1287 "FROM pg_catalog.pg_class c\n "
1288 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1289 "WHERE c.oid = '%s';",
1291 "pg_catalog.array_to_string(c.reloptions || "
1292 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1296 else if (pset.sversion >= 80400)
1298 printfPQExpBuffer(&buf,
1299 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1300 "c.relhastriggers, false, c.relhasoids, "
1301 "%s, c.reltablespace\n"
1302 "FROM pg_catalog.pg_class c\n "
1303 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1304 "WHERE c.oid = '%s';",
1306 "pg_catalog.array_to_string(c.reloptions || "
1307 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1311 else if (pset.sversion >= 80200)
1313 printfPQExpBuffer(&buf,
1314 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1315 "reltriggers <> 0, false, relhasoids, "
1316 "%s, reltablespace\n"
1317 "FROM pg_catalog.pg_class WHERE oid = '%s';",
1319 "pg_catalog.array_to_string(reloptions, E', ')" : "''"),
1322 else if (pset.sversion >= 80000)
1324 printfPQExpBuffer(&buf,
1325 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1326 "reltriggers <> 0, false, relhasoids, "
1327 "'', reltablespace\n"
1328 "FROM pg_catalog.pg_class WHERE oid = '%s';",
1333 printfPQExpBuffer(&buf,
1334 "SELECT relchecks, relkind, relhasindex, relhasrules, "
1335 "reltriggers <> 0, false, relhasoids, "
1337 "FROM pg_catalog.pg_class WHERE oid = '%s';",
1341 res = PSQLexec(buf.data, false);
1345 /* Did we get anything? */
1346 if (PQntuples(res) == 0)
1349 psql_error("Did not find any relation with OID %s.\n", oid);
1353 tableinfo.checks = atoi(PQgetvalue(res, 0, 0));
1354 tableinfo.relkind = *(PQgetvalue(res, 0, 1));
1355 tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 2), "t") == 0;
1356 tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 3), "t") == 0;
1357 tableinfo.hastriggers = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
1358 tableinfo.rowsecurity = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
1359 tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 6), "t") == 0;
1360 tableinfo.reloptions = (pset.sversion >= 80200) ?
1361 pg_strdup(PQgetvalue(res, 0, 7)) : NULL;
1362 tableinfo.tablespace = (pset.sversion >= 80000) ?
1363 atooid(PQgetvalue(res, 0, 8)) : 0;
1364 tableinfo.reloftype = (pset.sversion >= 90000 &&
1365 strcmp(PQgetvalue(res, 0, 9), "") != 0) ?
1366 pg_strdup(PQgetvalue(res, 0, 9)) : NULL;
1367 tableinfo.relpersistence = (pset.sversion >= 90100) ?
1368 *(PQgetvalue(res, 0, 10)) : 0;
1369 tableinfo.relreplident = (pset.sversion >= 90400) ?
1370 *(PQgetvalue(res, 0, 11)) : 'd';
1375 * If it's a sequence, fetch its values and store into an array that will
1378 if (tableinfo.relkind == 'S')
1380 printfPQExpBuffer(&buf, "SELECT * FROM %s", fmtId(schemaname));
1381 /* must be separate because fmtId isn't reentrant */
1382 appendPQExpBuffer(&buf, ".%s;", fmtId(relationname));
1384 res = PSQLexec(buf.data, false);
1388 seq_values = pg_malloc((PQnfields(res) + 1) * sizeof(*seq_values));
1390 for (i = 0; i < PQnfields(res); i++)
1391 seq_values[i] = pg_strdup(PQgetvalue(res, 0, i));
1392 seq_values[i] = NULL;
1401 * You need to modify value of "firstvcol" which will be defined below if
1402 * you are adding column(s) preceding to verbose-only columns.
1404 printfPQExpBuffer(&buf, "SELECT a.attname,");
1405 appendPQExpBufferStr(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod),"
1406 "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
1407 "\n FROM pg_catalog.pg_attrdef d"
1408 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
1409 "\n a.attnotnull, a.attnum,");
1410 if (pset.sversion >= 90100)
1411 appendPQExpBufferStr(&buf, "\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n"
1412 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1414 appendPQExpBufferStr(&buf, "\n NULL AS attcollation");
1415 if (tableinfo.relkind == 'i')
1416 appendPQExpBufferStr(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
1418 appendPQExpBufferStr(&buf, ",\n NULL AS indexdef");
1419 if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
1420 appendPQExpBufferStr(&buf, ",\n CASE WHEN attfdwoptions IS NULL THEN '' ELSE "
1421 " '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM "
1422 " pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1424 appendPQExpBufferStr(&buf, ",\n NULL AS attfdwoptions");
1427 appendPQExpBufferStr(&buf, ",\n a.attstorage");
1428 appendPQExpBufferStr(&buf, ",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1431 * In 9.0+, we have column comments for: relations, views, composite
1432 * types, and foreign tables (c.f. CommentObject() in comment.c).
1434 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1435 tableinfo.relkind == 'm' ||
1436 tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
1437 appendPQExpBufferStr(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
1440 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_attribute a");
1441 appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1442 appendPQExpBufferStr(&buf, "\nORDER BY a.attnum;");
1444 res = PSQLexec(buf.data, false);
1447 numrows = PQntuples(res);
1450 switch (tableinfo.relkind)
1453 if (tableinfo.relpersistence == 'u')
1454 printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
1455 schemaname, relationname);
1457 printfPQExpBuffer(&title, _("Table \"%s.%s\""),
1458 schemaname, relationname);
1461 printfPQExpBuffer(&title, _("View \"%s.%s\""),
1462 schemaname, relationname);
1465 if (tableinfo.relpersistence == 'u')
1466 printfPQExpBuffer(&title, _("Unlogged materialized view \"%s.%s\""),
1467 schemaname, relationname);
1469 printfPQExpBuffer(&title, _("Materialized view \"%s.%s\""),
1470 schemaname, relationname);
1473 printfPQExpBuffer(&title, _("Sequence \"%s.%s\""),
1474 schemaname, relationname);
1477 if (tableinfo.relpersistence == 'u')
1478 printfPQExpBuffer(&title, _("Unlogged index \"%s.%s\""),
1479 schemaname, relationname);
1481 printfPQExpBuffer(&title, _("Index \"%s.%s\""),
1482 schemaname, relationname);
1485 /* not used as of 8.2, but keep it for backwards compatibility */
1486 printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
1487 schemaname, relationname);
1490 printfPQExpBuffer(&title, _("TOAST table \"%s.%s\""),
1491 schemaname, relationname);
1494 printfPQExpBuffer(&title, _("Composite type \"%s.%s\""),
1495 schemaname, relationname);
1498 printfPQExpBuffer(&title, _("Foreign table \"%s.%s\""),
1499 schemaname, relationname);
1502 /* untranslated unknown relkind */
1503 printfPQExpBuffer(&title, "?%c? \"%s.%s\"",
1504 tableinfo.relkind, schemaname, relationname);
1508 /* Set the number of columns, and their names */
1509 headers[0] = gettext_noop("Column");
1510 headers[1] = gettext_noop("Type");
1513 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1514 tableinfo.relkind == 'm' ||
1515 tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
1517 show_modifiers = true;
1518 headers[cols++] = gettext_noop("Modifiers");
1519 modifiers = pg_malloc0((numrows + 1) * sizeof(*modifiers));
1522 if (tableinfo.relkind == 'S')
1523 headers[cols++] = gettext_noop("Value");
1525 if (tableinfo.relkind == 'i')
1526 headers[cols++] = gettext_noop("Definition");
1528 if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
1529 headers[cols++] = gettext_noop("FDW Options");
1533 headers[cols++] = gettext_noop("Storage");
1534 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
1535 tableinfo.relkind == 'f')
1536 headers[cols++] = gettext_noop("Stats target");
1537 /* Column comments, if the relkind supports this feature. */
1538 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1539 tableinfo.relkind == 'm' ||
1540 tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
1541 headers[cols++] = gettext_noop("Description");
1544 printTableInit(&cont, &myopt, title.data, cols, numrows);
1545 printTableInitialized = true;
1547 for (i = 0; i < cols; i++)
1548 printTableAddHeader(&cont, headers[i], true, 'l');
1550 /* Check if table is a view or materialized view */
1551 if ((tableinfo.relkind == 'v' || tableinfo.relkind == 'm') && verbose)
1555 printfPQExpBuffer(&buf,
1556 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
1558 result = PSQLexec(buf.data, false);
1562 if (PQntuples(result) > 0)
1563 view_def = pg_strdup(PQgetvalue(result, 0, 0));
1568 /* Generate table cells to be printed */
1569 for (i = 0; i < numrows; i++)
1572 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
1575 printTableAddCell(&cont, PQgetvalue(res, i, 1), false, false);
1577 /* Modifiers: collate, not null, default */
1580 resetPQExpBuffer(&tmpbuf);
1582 if (!PQgetisnull(res, i, 5))
1585 appendPQExpBufferStr(&tmpbuf, " ");
1586 appendPQExpBuffer(&tmpbuf, _("collate %s"),
1587 PQgetvalue(res, i, 5));
1590 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
1593 appendPQExpBufferStr(&tmpbuf, " ");
1594 appendPQExpBufferStr(&tmpbuf, _("not null"));
1597 /* handle "default" here */
1598 /* (note: above we cut off the 'default' string at 128) */
1599 if (strlen(PQgetvalue(res, i, 2)) != 0)
1602 appendPQExpBufferStr(&tmpbuf, " ");
1603 /* translator: default values of column definitions */
1604 appendPQExpBuffer(&tmpbuf, _("default %s"),
1605 PQgetvalue(res, i, 2));
1608 modifiers[i] = pg_strdup(tmpbuf.data);
1609 printTableAddCell(&cont, modifiers[i], false, false);
1612 /* Value: for sequences only */
1613 if (tableinfo.relkind == 'S')
1614 printTableAddCell(&cont, seq_values[i], false, false);
1616 /* Expression for index column */
1617 if (tableinfo.relkind == 'i')
1618 printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
1620 /* FDW options for foreign table column, only for 9.2 or later */
1621 if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
1622 printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
1624 /* Storage and Description */
1628 char *storage = PQgetvalue(res, i, firstvcol);
1630 /* these strings are literal in our syntax, so not translated. */
1631 printTableAddCell(&cont, (storage[0] == 'p' ? "plain" :
1632 (storage[0] == 'm' ? "main" :
1633 (storage[0] == 'x' ? "extended" :
1634 (storage[0] == 'e' ? "external" :
1638 /* Statistics target, if the relkind supports this feature */
1639 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
1640 tableinfo.relkind == 'f')
1642 printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1646 /* Column comments, if the relkind supports this feature. */
1647 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
1648 tableinfo.relkind == 'm' ||
1649 tableinfo.relkind == 'c' || tableinfo.relkind == 'f')
1650 printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 2),
1656 if (tableinfo.relkind == 'i')
1658 /* Footer information about an index */
1661 printfPQExpBuffer(&buf,
1662 "SELECT i.indisunique, i.indisprimary, i.indisclustered, ");
1663 if (pset.sversion >= 80200)
1664 appendPQExpBufferStr(&buf, "i.indisvalid,\n");
1666 appendPQExpBufferStr(&buf, "true AS indisvalid,\n");
1667 if (pset.sversion >= 90000)
1668 appendPQExpBufferStr(&buf,
1669 " (NOT i.indimmediate) AND "
1670 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
1671 "WHERE conrelid = i.indrelid AND "
1672 "conindid = i.indexrelid AND "
1673 "contype IN ('p','u','x') AND "
1674 "condeferrable) AS condeferrable,\n"
1675 " (NOT i.indimmediate) AND "
1676 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
1677 "WHERE conrelid = i.indrelid AND "
1678 "conindid = i.indexrelid AND "
1679 "contype IN ('p','u','x') AND "
1680 "condeferred) AS condeferred,\n");
1682 appendPQExpBufferStr(&buf,
1683 " false AS condeferrable, false AS condeferred,\n");
1685 if (pset.sversion >= 90400)
1686 appendPQExpBuffer(&buf, "i.indisreplident,\n");
1688 appendPQExpBuffer(&buf, "false AS indisreplident,\n");
1690 appendPQExpBuffer(&buf, " a.amname, c2.relname, "
1691 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
1692 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
1693 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
1694 "AND i.indrelid = c2.oid;",
1697 result = PSQLexec(buf.data, false);
1700 else if (PQntuples(result) != 1)
1707 char *indisunique = PQgetvalue(result, 0, 0);
1708 char *indisprimary = PQgetvalue(result, 0, 1);
1709 char *indisclustered = PQgetvalue(result, 0, 2);
1710 char *indisvalid = PQgetvalue(result, 0, 3);
1711 char *deferrable = PQgetvalue(result, 0, 4);
1712 char *deferred = PQgetvalue(result, 0, 5);
1713 char *indisreplident = PQgetvalue(result, 0, 6);
1714 char *indamname = PQgetvalue(result, 0, 7);
1715 char *indtable = PQgetvalue(result, 0, 8);
1716 char *indpred = PQgetvalue(result, 0, 9);
1718 if (strcmp(indisprimary, "t") == 0)
1719 printfPQExpBuffer(&tmpbuf, _("primary key, "));
1720 else if (strcmp(indisunique, "t") == 0)
1721 printfPQExpBuffer(&tmpbuf, _("unique, "));
1723 resetPQExpBuffer(&tmpbuf);
1724 appendPQExpBuffer(&tmpbuf, "%s, ", indamname);
1726 /* we assume here that index and table are in same schema */
1727 appendPQExpBuffer(&tmpbuf, _("for table \"%s.%s\""),
1728 schemaname, indtable);
1730 if (strlen(indpred))
1731 appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred);
1733 if (strcmp(indisclustered, "t") == 0)
1734 appendPQExpBufferStr(&tmpbuf, _(", clustered"));
1736 if (strcmp(indisvalid, "t") != 0)
1737 appendPQExpBufferStr(&tmpbuf, _(", invalid"));
1739 if (strcmp(deferrable, "t") == 0)
1740 appendPQExpBufferStr(&tmpbuf, _(", deferrable"));
1742 if (strcmp(deferred, "t") == 0)
1743 appendPQExpBufferStr(&tmpbuf, _(", initially deferred"));
1745 if (strcmp(indisreplident, "t") == 0)
1746 appendPQExpBuffer(&tmpbuf, _(", replica identity"));
1748 printTableAddFooter(&cont, tmpbuf.data);
1749 add_tablespace_footer(&cont, tableinfo.relkind,
1750 tableinfo.tablespace, true);
1755 else if (tableinfo.relkind == 'S')
1757 /* Footer information about a sequence */
1758 PGresult *result = NULL;
1760 /* Get the column that owns this sequence */
1761 printfPQExpBuffer(&buf, "SELECT pg_catalog.quote_ident(nspname) || '.' ||"
1762 "\n pg_catalog.quote_ident(relname) || '.' ||"
1763 "\n pg_catalog.quote_ident(attname)"
1764 "\nFROM pg_catalog.pg_class c"
1765 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1766 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1767 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1768 "\n a.attrelid=c.oid AND"
1769 "\n a.attnum=d.refobjsubid)"
1770 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1771 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1773 "\n AND d.deptype='a'",
1776 result = PSQLexec(buf.data, false);
1779 else if (PQntuples(result) == 1)
1781 printfPQExpBuffer(&buf, _("Owned by: %s"),
1782 PQgetvalue(result, 0, 0));
1783 printTableAddFooter(&cont, buf.data);
1787 * If we get no rows back, don't show anything (obviously). We should
1788 * never get more than one row back, but if we do, just ignore it and
1789 * don't print anything.
1793 else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
1794 tableinfo.relkind == 'f')
1796 /* Footer information about a table */
1797 PGresult *result = NULL;
1801 if (tableinfo.hasindex)
1803 printfPQExpBuffer(&buf,
1804 "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, ");
1805 if (pset.sversion >= 80200)
1806 appendPQExpBufferStr(&buf, "i.indisvalid, ");
1808 appendPQExpBufferStr(&buf, "true as indisvalid, ");
1809 appendPQExpBufferStr(&buf, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n ");
1810 if (pset.sversion >= 90000)
1811 appendPQExpBufferStr(&buf,
1812 "pg_catalog.pg_get_constraintdef(con.oid, true), "
1813 "contype, condeferrable, condeferred");
1815 appendPQExpBufferStr(&buf,
1816 "null AS constraintdef, null AS contype, "
1817 "false AS condeferrable, false AS condeferred");
1818 if (pset.sversion >= 90400)
1819 appendPQExpBufferStr(&buf, ", i.indisreplident");
1821 appendPQExpBufferStr(&buf, ", false AS indisreplident");
1822 if (pset.sversion >= 80000)
1823 appendPQExpBufferStr(&buf, ", c2.reltablespace");
1824 appendPQExpBufferStr(&buf,
1825 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n");
1826 if (pset.sversion >= 90000)
1827 appendPQExpBufferStr(&buf,
1828 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
1829 appendPQExpBuffer(&buf,
1830 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
1831 "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;",
1833 result = PSQLexec(buf.data, false);
1837 tuples = PQntuples(result);
1841 printTableAddFooter(&cont, _("Indexes:"));
1842 for (i = 0; i < tuples; i++)
1844 /* untranslated index name */
1845 printfPQExpBuffer(&buf, " \"%s\"",
1846 PQgetvalue(result, i, 0));
1848 /* If exclusion constraint, print the constraintdef */
1849 if (strcmp(PQgetvalue(result, i, 7), "x") == 0)
1851 appendPQExpBuffer(&buf, " %s",
1852 PQgetvalue(result, i, 6));
1856 const char *indexdef;
1857 const char *usingpos;
1859 /* Label as primary key or unique (but not both) */
1860 if (strcmp(PQgetvalue(result, i, 1), "t") == 0)
1861 appendPQExpBufferStr(&buf, " PRIMARY KEY,");
1862 else if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
1864 if (strcmp(PQgetvalue(result, i, 7), "u") == 0)
1865 appendPQExpBufferStr(&buf, " UNIQUE CONSTRAINT,");
1867 appendPQExpBufferStr(&buf, " UNIQUE,");
1870 /* Everything after "USING" is echoed verbatim */
1871 indexdef = PQgetvalue(result, i, 5);
1872 usingpos = strstr(indexdef, " USING ");
1874 indexdef = usingpos + 7;
1875 appendPQExpBuffer(&buf, " %s", indexdef);
1877 /* Need these for deferrable PK/UNIQUE indexes */
1878 if (strcmp(PQgetvalue(result, i, 8), "t") == 0)
1879 appendPQExpBufferStr(&buf, " DEFERRABLE");
1881 if (strcmp(PQgetvalue(result, i, 9), "t") == 0)
1882 appendPQExpBufferStr(&buf, " INITIALLY DEFERRED");
1885 /* Add these for all cases */
1886 if (strcmp(PQgetvalue(result, i, 3), "t") == 0)
1887 appendPQExpBufferStr(&buf, " CLUSTER");
1889 if (strcmp(PQgetvalue(result, i, 4), "t") != 0)
1890 appendPQExpBufferStr(&buf, " INVALID");
1892 if (strcmp(PQgetvalue(result, i, 10), "t") == 0)
1893 appendPQExpBuffer(&buf, " REPLICA IDENTITY");
1895 printTableAddFooter(&cont, buf.data);
1897 /* Print tablespace of the index on the same line */
1898 if (pset.sversion >= 80000)
1899 add_tablespace_footer(&cont, 'i',
1900 atooid(PQgetvalue(result, i, 11)),
1907 /* print table (and column) check constraints */
1908 if (tableinfo.checks)
1910 printfPQExpBuffer(&buf,
1911 "SELECT r.conname, "
1912 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
1913 "FROM pg_catalog.pg_constraint r\n"
1914 "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
1917 result = PSQLexec(buf.data, false);
1921 tuples = PQntuples(result);
1925 printTableAddFooter(&cont, _("Check constraints:"));
1926 for (i = 0; i < tuples; i++)
1928 /* untranslated contraint name and def */
1929 printfPQExpBuffer(&buf, " \"%s\" %s",
1930 PQgetvalue(result, i, 0),
1931 PQgetvalue(result, i, 1));
1933 printTableAddFooter(&cont, buf.data);
1939 /* print foreign-key constraints (there are none if no triggers) */
1940 if (tableinfo.hastriggers)
1942 printfPQExpBuffer(&buf,
1944 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef\n"
1945 "FROM pg_catalog.pg_constraint r\n"
1946 "WHERE r.conrelid = '%s' AND r.contype = 'f' ORDER BY 1;",
1948 result = PSQLexec(buf.data, false);
1952 tuples = PQntuples(result);
1956 printTableAddFooter(&cont, _("Foreign-key constraints:"));
1957 for (i = 0; i < tuples; i++)
1959 /* untranslated constraint name and def */
1960 printfPQExpBuffer(&buf, " \"%s\" %s",
1961 PQgetvalue(result, i, 0),
1962 PQgetvalue(result, i, 1));
1964 printTableAddFooter(&cont, buf.data);
1970 /* print incoming foreign-key references (none if no triggers) */
1971 if (tableinfo.hastriggers)
1973 printfPQExpBuffer(&buf,
1974 "SELECT conname, conrelid::pg_catalog.regclass,\n"
1975 " pg_catalog.pg_get_constraintdef(c.oid, true) as condef\n"
1976 "FROM pg_catalog.pg_constraint c\n"
1977 "WHERE c.confrelid = '%s' AND c.contype = 'f' ORDER BY 1;",
1979 result = PSQLexec(buf.data, false);
1983 tuples = PQntuples(result);
1987 printTableAddFooter(&cont, _("Referenced by:"));
1988 for (i = 0; i < tuples; i++)
1990 printfPQExpBuffer(&buf, " TABLE \"%s\" CONSTRAINT \"%s\" %s",
1991 PQgetvalue(result, i, 1),
1992 PQgetvalue(result, i, 0),
1993 PQgetvalue(result, i, 2));
1995 printTableAddFooter(&cont, buf.data);
2001 /* print any row-level policies */
2002 if (pset.sversion >= 90500)
2004 appendPQExpBuffer(&buf,
2005 ",\n pg_catalog.pg_get_expr(rs.rsecqual, c.oid) as \"%s\"",
2006 gettext_noop("Row-security"));
2009 appendPQExpBuffer(&buf,
2010 "\n LEFT JOIN pg_rowsecurity rs ON rs.rsecrelid = c.oid");
2012 printfPQExpBuffer(&buf,
2013 "SELECT rs.rsecpolname,\n"
2014 "CASE WHEN rs.rsecroles = '{0}' THEN NULL ELSE array_to_string(array(select rolname from pg_roles where oid = any (rs.rsecroles) order by 1),',') END,\n"
2015 "pg_catalog.pg_get_expr(rs.rsecqual, rs.rsecrelid),\n"
2016 "pg_catalog.pg_get_expr(rs.rsecwithcheck, rs.rsecrelid),\n"
2017 "CASE rs.rseccmd \n"
2018 "WHEN 'r' THEN 'SELECT'\n"
2019 "WHEN 'u' THEN 'UPDATE'\n"
2020 "WHEN 'a' THEN 'INSERT'\n"
2021 "WHEN 'd' THEN 'DELETE'\n"
2023 "FROM pg_catalog.pg_rowsecurity rs\n"
2024 "WHERE rs.rsecrelid = '%s' ORDER BY 1;",
2027 result = PSQLexec(buf.data, false);
2031 tuples = PQntuples(result);
2034 * Handle cases where RLS is enabled and there are policies,
2035 * or there aren't policies, or RLS isn't enabled but there
2038 if (tableinfo.rowsecurity && tuples > 0)
2039 printTableAddFooter(&cont, _("Policies:"));
2041 if (tableinfo.rowsecurity && tuples == 0)
2042 printTableAddFooter(&cont, _("Policies (Row Security Enabled): (None)"));
2044 if (!tableinfo.rowsecurity && tuples > 0)
2045 printTableAddFooter(&cont, _("Policies (Row Security Disabled):"));
2047 /* Might be an empty set - that's ok */
2048 for (i = 0; i < tuples; i++)
2050 printfPQExpBuffer(&buf, " POLICY \"%s\"",
2051 PQgetvalue(result, i, 0));
2053 if (!PQgetisnull(result, i, 4))
2054 appendPQExpBuffer(&buf, " FOR %s",
2055 PQgetvalue(result, i, 4));
2057 if (!PQgetisnull(result, i, 1))
2059 appendPQExpBuffer(&buf, "\n TO %s",
2060 PQgetvalue(result, i, 1));
2063 if (!PQgetisnull(result, i, 2))
2064 appendPQExpBuffer(&buf, "\n USING %s",
2065 PQgetvalue(result, i, 2));
2067 if (!PQgetisnull(result, i, 3))
2068 appendPQExpBuffer(&buf, "\n WITH CHECK %s",
2069 PQgetvalue(result, i, 3));
2071 printTableAddFooter(&cont, buf.data);
2078 if (tableinfo.hasrules && tableinfo.relkind != 'm')
2080 if (pset.sversion >= 80300)
2082 printfPQExpBuffer(&buf,
2083 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2085 "FROM pg_catalog.pg_rewrite r\n"
2086 "WHERE r.ev_class = '%s' ORDER BY 1;",
2091 printfPQExpBuffer(&buf,
2092 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2093 "'O'::char AS ev_enabled\n"
2094 "FROM pg_catalog.pg_rewrite r\n"
2095 "WHERE r.ev_class = '%s' ORDER BY 1;",
2098 result = PSQLexec(buf.data, false);
2102 tuples = PQntuples(result);
2109 for (category = 0; category < 4; category++)
2111 have_heading = false;
2113 for (i = 0; i < tuples; i++)
2115 const char *ruledef;
2116 bool list_rule = false;
2121 if (*PQgetvalue(result, i, 2) == 'O')
2125 if (*PQgetvalue(result, i, 2) == 'D')
2129 if (*PQgetvalue(result, i, 2) == 'A')
2133 if (*PQgetvalue(result, i, 2) == 'R')
2145 printfPQExpBuffer(&buf, _("Rules:"));
2148 printfPQExpBuffer(&buf, _("Disabled rules:"));
2151 printfPQExpBuffer(&buf, _("Rules firing always:"));
2154 printfPQExpBuffer(&buf, _("Rules firing on replica only:"));
2157 printTableAddFooter(&cont, buf.data);
2158 have_heading = true;
2161 /* Everything after "CREATE RULE" is echoed verbatim */
2162 ruledef = PQgetvalue(result, i, 1);
2164 printfPQExpBuffer(&buf, " %s", ruledef);
2165 printTableAddFooter(&cont, buf.data);
2175 PGresult *result = NULL;
2177 /* Footer information about a view */
2178 printTableAddFooter(&cont, _("View definition:"));
2179 printTableAddFooter(&cont, view_def);
2182 if (tableinfo.hasrules)
2184 printfPQExpBuffer(&buf,
2185 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
2186 "FROM pg_catalog.pg_rewrite r\n"
2187 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
2189 result = PSQLexec(buf.data, false);
2193 if (PQntuples(result) > 0)
2195 printTableAddFooter(&cont, _("Rules:"));
2196 for (i = 0; i < PQntuples(result); i++)
2198 const char *ruledef;
2200 /* Everything after "CREATE RULE" is echoed verbatim */
2201 ruledef = PQgetvalue(result, i, 1);
2204 printfPQExpBuffer(&buf, " %s", ruledef);
2205 printTableAddFooter(&cont, buf.data);
2213 * Print triggers next, if any (but only user-defined triggers). This
2214 * could apply to either a table or a view.
2216 if (tableinfo.hastriggers)
2221 printfPQExpBuffer(&buf,
2223 "pg_catalog.pg_get_triggerdef(t.oid%s), "
2225 "FROM pg_catalog.pg_trigger t\n"
2226 "WHERE t.tgrelid = '%s' AND ",
2227 (pset.sversion >= 90000 ? ", true" : ""),
2228 (pset.sversion >= 90000 ? "t.tgisinternal" :
2229 pset.sversion >= 80300 ?
2230 "t.tgconstraint <> 0 AS tgisinternal" :
2231 "false AS tgisinternal"), oid);
2232 if (pset.sversion >= 90000)
2233 /* display/warn about disabled internal triggers */
2234 appendPQExpBuffer(&buf, "(NOT t.tgisinternal OR (t.tgisinternal AND t.tgenabled = 'D'))");
2235 else if (pset.sversion >= 80300)
2236 appendPQExpBufferStr(&buf, "(t.tgconstraint = 0 OR (t.tgconstraint <> 0 AND t.tgenabled = 'D'))");
2238 appendPQExpBufferStr(&buf,
2239 "(NOT tgisconstraint "
2241 " (SELECT 1 FROM pg_catalog.pg_depend d "
2242 " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
2243 " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
2244 appendPQExpBufferStr(&buf, "\nORDER BY 1;");
2246 result = PSQLexec(buf.data, false);
2250 tuples = PQntuples(result);
2258 * split the output into 4 different categories. Enabled triggers,
2259 * disabled triggers and the two special ALWAYS and REPLICA
2262 for (category = 0; category <= 4; category++)
2264 have_heading = false;
2265 for (i = 0; i < tuples; i++)
2269 const char *usingpos;
2270 const char *tgenabled;
2271 const char *tgisinternal;
2274 * Check if this trigger falls into the current category
2276 tgenabled = PQgetvalue(result, i, 2);
2277 tgisinternal = PQgetvalue(result, i, 3);
2278 list_trigger = false;
2282 if (*tgenabled == 'O' || *tgenabled == 't')
2283 list_trigger = true;
2286 if ((*tgenabled == 'D' || *tgenabled == 'f') &&
2287 *tgisinternal == 'f')
2288 list_trigger = true;
2291 if ((*tgenabled == 'D' || *tgenabled == 'f') &&
2292 *tgisinternal == 't')
2293 list_trigger = true;
2296 if (*tgenabled == 'A')
2297 list_trigger = true;
2300 if (*tgenabled == 'R')
2301 list_trigger = true;
2304 if (list_trigger == false)
2307 /* Print the category heading once */
2308 if (have_heading == false)
2313 printfPQExpBuffer(&buf, _("Triggers:"));
2316 if (pset.sversion >= 80300)
2317 printfPQExpBuffer(&buf, _("Disabled user triggers:"));
2319 printfPQExpBuffer(&buf, _("Disabled triggers:"));
2322 printfPQExpBuffer(&buf, _("Disabled internal triggers:"));
2325 printfPQExpBuffer(&buf, _("Triggers firing always:"));
2328 printfPQExpBuffer(&buf, _("Triggers firing on replica only:"));
2332 printTableAddFooter(&cont, buf.data);
2333 have_heading = true;
2336 /* Everything after "TRIGGER" is echoed verbatim */
2337 tgdef = PQgetvalue(result, i, 1);
2338 usingpos = strstr(tgdef, " TRIGGER ");
2340 tgdef = usingpos + 9;
2342 printfPQExpBuffer(&buf, " %s", tgdef);
2343 printTableAddFooter(&cont, buf.data);
2351 * Finish printing the footer information about a table.
2353 if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
2354 tableinfo.relkind == 'f')
2359 /* print foreign server name */
2360 if (tableinfo.relkind == 'f')
2364 /* Footer information about foreign table */
2365 printfPQExpBuffer(&buf,
2366 "SELECT s.srvname,\n"
2367 " array_to_string(ARRAY(SELECT "
2368 " quote_ident(option_name) || ' ' || "
2369 " quote_literal(option_value) FROM "
2370 " pg_options_to_table(ftoptions)), ', ') "
2371 "FROM pg_catalog.pg_foreign_table f,\n"
2372 " pg_catalog.pg_foreign_server s\n"
2373 "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
2375 result = PSQLexec(buf.data, false);
2378 else if (PQntuples(result) != 1)
2384 /* Print server name */
2385 printfPQExpBuffer(&buf, "Server: %s",
2386 PQgetvalue(result, 0, 0));
2387 printTableAddFooter(&cont, buf.data);
2389 /* Print per-table FDW options, if any */
2390 ftoptions = PQgetvalue(result, 0, 1);
2391 if (ftoptions && ftoptions[0] != '\0')
2393 printfPQExpBuffer(&buf, "FDW Options: (%s)", ftoptions);
2394 printTableAddFooter(&cont, buf.data);
2399 /* print inherited tables */
2400 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno;", oid);
2402 result = PSQLexec(buf.data, false);
2407 const char *s = _("Inherits");
2408 int sw = pg_wcswidth(s, strlen(s), pset.encoding);
2410 tuples = PQntuples(result);
2412 for (i = 0; i < tuples; i++)
2415 printfPQExpBuffer(&buf, "%s: %s",
2416 s, PQgetvalue(result, i, 0));
2418 printfPQExpBuffer(&buf, "%*s %s",
2419 sw, "", PQgetvalue(result, i, 0));
2421 appendPQExpBufferStr(&buf, ",");
2423 printTableAddFooter(&cont, buf.data);
2429 /* print child tables */
2430 if (pset.sversion >= 80300)
2431 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;", oid);
2433 printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.relname;", oid);
2435 result = PSQLexec(buf.data, false);
2439 tuples = PQntuples(result);
2443 /* print the number of child tables, if any */
2446 printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples);
2447 printTableAddFooter(&cont, buf.data);
2452 /* display the list of child tables */
2453 const char *ct = _("Child tables");
2454 int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
2456 for (i = 0; i < tuples; i++)
2459 printfPQExpBuffer(&buf, "%s: %s",
2460 ct, PQgetvalue(result, i, 0));
2462 printfPQExpBuffer(&buf, "%*s %s",
2463 ctw, "", PQgetvalue(result, i, 0));
2465 appendPQExpBufferChar(&buf, ',');
2467 printTableAddFooter(&cont, buf.data);
2473 if (tableinfo.reloftype)
2475 printfPQExpBuffer(&buf, _("Typed table of type: %s"), tableinfo.reloftype);
2476 printTableAddFooter(&cont, buf.data);
2479 if (verbose && (tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
2482 * No need to display default values; we already display a REPLICA
2483 * IDENTITY marker on indexes.
2485 tableinfo.relreplident != 'i' &&
2486 ((strcmp(schemaname, "pg_catalog") != 0 && tableinfo.relreplident != 'd') ||
2487 (strcmp(schemaname, "pg_catalog") == 0 && tableinfo.relreplident != 'n')))
2489 const char *s = _("Replica Identity");
2491 printfPQExpBuffer(&buf, "%s: %s",
2493 tableinfo.relreplident == 'f' ? "FULL" :
2494 tableinfo.relreplident == 'n' ? "NOTHING" :
2497 printTableAddFooter(&cont, buf.data);
2500 /* OIDs, if verbose and not a materialized view */
2501 if (verbose && tableinfo.relkind != 'm' && tableinfo.hasoids)
2502 printTableAddFooter(&cont, _("Has OIDs: yes"));
2504 /* Tablespace info */
2505 add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,
2509 /* reloptions, if verbose */
2511 tableinfo.reloptions && tableinfo.reloptions[0] != '\0')
2513 const char *t = _("Options");
2515 printfPQExpBuffer(&buf, "%s: %s", t, tableinfo.reloptions);
2516 printTableAddFooter(&cont, buf.data);
2519 printTable(&cont, pset.queryFout, pset.logfile);
2520 printTableCleanup(&cont);
2527 if (printTableInitialized)
2528 printTableCleanup(&cont);
2529 termPQExpBuffer(&buf);
2530 termPQExpBuffer(&title);
2531 termPQExpBuffer(&tmpbuf);
2535 for (ptr = seq_values; *ptr; ptr++)
2542 for (ptr = modifiers; *ptr; ptr++)
2557 * Add a tablespace description to a footer. If 'newline' is true, it is added
2558 * in a new line; otherwise it's appended to the current value of the last
2562 add_tablespace_footer(printTableContent *const cont, char relkind,
2563 Oid tablespace, const bool newline)
2565 /* relkinds for which we support tablespaces */
2566 if (relkind == 'r' || relkind == 'm' || relkind == 'i')
2569 * We ignore the database default tablespace so that users not using
2570 * tablespaces don't need to know about them. This case also covers
2571 * pre-8.0 servers, for which tablespace will always be 0.
2573 if (tablespace != 0)
2575 PGresult *result = NULL;
2576 PQExpBufferData buf;
2578 initPQExpBuffer(&buf);
2579 printfPQExpBuffer(&buf,
2580 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
2581 "WHERE oid = '%u';", tablespace);
2582 result = PSQLexec(buf.data, false);
2585 /* Should always be the case, but.... */
2586 if (PQntuples(result) > 0)
2590 /* Add the tablespace as a new footer */
2591 printfPQExpBuffer(&buf, _("Tablespace: \"%s\""),
2592 PQgetvalue(result, 0, 0));
2593 printTableAddFooter(cont, buf.data);
2597 /* Append the tablespace to the latest footer */
2598 printfPQExpBuffer(&buf, "%s", cont->footer->data);
2601 translator: before this string there's an index description like
2602 '"foo_pkey" PRIMARY KEY, btree (a)' */
2603 appendPQExpBuffer(&buf, _(", tablespace \"%s\""),
2604 PQgetvalue(result, 0, 0));
2605 printTableSetFooter(cont, buf.data);
2609 termPQExpBuffer(&buf);
2617 * Describes roles. Any schema portion of the pattern is ignored.
2620 describeRoles(const char *pattern, bool verbose)
2622 PQExpBufferData buf;
2624 printTableContent cont;
2625 printTableOpt myopt = pset.popt.topt;
2630 const char align = 'l';
2633 myopt.default_footer = false;
2635 initPQExpBuffer(&buf);
2637 if (pset.sversion >= 80100)
2639 printfPQExpBuffer(&buf,
2640 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
2641 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
2642 " r.rolconnlimit, r.rolvaliduntil,\n"
2643 " ARRAY(SELECT b.rolname\n"
2644 " FROM pg_catalog.pg_auth_members m\n"
2645 " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
2646 " WHERE m.member = r.oid) as memberof");
2648 if (verbose && pset.sversion >= 80200)
2650 appendPQExpBufferStr(&buf, "\n, pg_catalog.shobj_description(r.oid, 'pg_authid') AS description");
2653 if (pset.sversion >= 90100)
2655 appendPQExpBufferStr(&buf, "\n, r.rolreplication");
2658 if (pset.sversion >= 90500)
2660 appendPQExpBufferStr(&buf, "\n, r.rolbypassrls");
2663 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_roles r\n");
2665 processSQLNamePattern(pset.db, &buf, pattern, false, false,
2666 NULL, "r.rolname", NULL, NULL);
2670 printfPQExpBuffer(&buf,
2671 "SELECT u.usename AS rolname,\n"
2672 " u.usesuper AS rolsuper,\n"
2673 " true AS rolinherit, false AS rolcreaterole,\n"
2674 " u.usecreatedb AS rolcreatedb, true AS rolcanlogin,\n"
2675 " -1 AS rolconnlimit,"
2676 " u.valuntil as rolvaliduntil,\n"
2677 " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as memberof"
2678 "\nFROM pg_catalog.pg_user u\n");
2680 processSQLNamePattern(pset.db, &buf, pattern, false, false,
2681 NULL, "u.usename", NULL, NULL);
2684 appendPQExpBufferStr(&buf, "ORDER BY 1;");
2686 res = PSQLexec(buf.data, false);
2690 nrows = PQntuples(res);
2691 attr = pg_malloc0((nrows + 1) * sizeof(*attr));
2693 printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
2695 printTableAddHeader(&cont, gettext_noop("Role name"), true, align);
2696 printTableAddHeader(&cont, gettext_noop("Attributes"), true, align);
2697 printTableAddHeader(&cont, gettext_noop("Member of"), true, align);
2699 if (verbose && pset.sversion >= 80200)
2700 printTableAddHeader(&cont, gettext_noop("Description"), true, align);
2702 for (i = 0; i < nrows; i++)
2704 printTableAddCell(&cont, PQgetvalue(res, i, 0), false, false);
2706 resetPQExpBuffer(&buf);
2707 if (strcmp(PQgetvalue(res, i, 1), "t") == 0)
2708 add_role_attribute(&buf, _("Superuser"));
2710 if (strcmp(PQgetvalue(res, i, 2), "t") != 0)
2711 add_role_attribute(&buf, _("No inheritance"));
2713 if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
2714 add_role_attribute(&buf, _("Create role"));
2716 if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
2717 add_role_attribute(&buf, _("Create DB"));
2719 if (strcmp(PQgetvalue(res, i, 5), "t") != 0)
2720 add_role_attribute(&buf, _("Cannot login"));
2722 if (pset.sversion >= 90100)
2723 if (strcmp(PQgetvalue(res, i, (verbose ? 10 : 9)), "t") == 0)
2724 add_role_attribute(&buf, _("Replication"));
2726 if (pset.sversion >= 90500)
2727 if (strcmp(PQgetvalue(res, i, (verbose ? 11 : 10)), "t") == 0)
2728 add_role_attribute(&buf, _("Bypass RLS"));
2730 conns = atoi(PQgetvalue(res, i, 6));
2734 appendPQExpBufferChar(&buf, '\n');
2737 appendPQExpBufferStr(&buf, _("No connections"));
2739 appendPQExpBuffer(&buf, ngettext("%d connection",
2745 if (strcmp(PQgetvalue(res, i, 7), "") != 0)
2748 appendPQExpBufferStr(&buf, "\n");
2749 appendPQExpBufferStr(&buf, _("Password valid until "));
2750 appendPQExpBufferStr(&buf, PQgetvalue(res, i, 7));
2753 attr[i] = pg_strdup(buf.data);
2755 printTableAddCell(&cont, attr[i], false, false);
2757 printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
2759 if (verbose && pset.sversion >= 80200)
2760 printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
2762 termPQExpBuffer(&buf);
2764 printTable(&cont, pset.queryFout, pset.logfile);
2765 printTableCleanup(&cont);
2767 for (i = 0; i < nrows; i++)
2776 add_role_attribute(PQExpBuffer buf, const char *const str)
2779 appendPQExpBufferStr(buf, ", ");
2781 appendPQExpBufferStr(buf, str);
2788 listDbRoleSettings(const char *pattern, const char *pattern2)
2790 PQExpBufferData buf;
2792 printQueryOpt myopt = pset.popt;
2794 initPQExpBuffer(&buf);
2796 if (pset.sversion >= 90000)
2800 printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
2801 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
2802 "FROM pg_db_role_setting AS s\n"
2803 "LEFT JOIN pg_database ON pg_database.oid = setdatabase\n"
2804 "LEFT JOIN pg_roles ON pg_roles.oid = setrole\n",
2805 gettext_noop("Role"),
2806 gettext_noop("Database"),
2807 gettext_noop("Settings"));
2808 havewhere = processSQLNamePattern(pset.db, &buf, pattern, false, false,
2809 NULL, "pg_roles.rolname", NULL, NULL);
2810 processSQLNamePattern(pset.db, &buf, pattern2, havewhere, false,
2811 NULL, "pg_database.datname", NULL, NULL);
2812 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
2816 fprintf(pset.queryFout,
2817 _("No per-database role settings support in this server version.\n"));
2821 res = PSQLexec(buf.data, false);
2825 if (PQntuples(res) == 0 && !pset.quiet)
2828 fprintf(pset.queryFout, _("No matching settings found.\n"));
2830 fprintf(pset.queryFout, _("No settings found.\n"));
2834 myopt.nullPrint = NULL;
2835 myopt.title = _("List of settings");
2836 myopt.translate_header = true;
2838 printQuery(res, &myopt, pset.queryFout, pset.logfile);
2842 resetPQExpBuffer(&buf);
2850 * handler for \dt, \di, etc.
2852 * tabtypes is an array of characters, specifying what info is desired:
2856 * m - materialized views
2858 * E - foreign table (Note: different from 'f', the relkind value)
2859 * (any order of the above is fine)
2860 * If tabtypes is empty, we default to \dtvsE.
2863 listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
2865 bool showTables = strchr(tabtypes, 't') != NULL;
2866 bool showIndexes = strchr(tabtypes, 'i') != NULL;
2867 bool showViews = strchr(tabtypes, 'v') != NULL;
2868 bool showMatViews = strchr(tabtypes, 'm') != NULL;
2869 bool showSeq = strchr(tabtypes, 's') != NULL;
2870 bool showForeign = strchr(tabtypes, 'E') != NULL;
2872 PQExpBufferData buf;
2874 printQueryOpt myopt = pset.popt;
2875 static const bool translate_columns[] = {false, false, true, false, false, false, false};
2877 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
2878 showTables = showViews = showMatViews = showSeq = showForeign = true;
2880 initPQExpBuffer(&buf);
2883 * Note: as of Pg 8.2, we no longer use relkind 's', but we keep it here
2884 * for backwards compatibility.
2886 printfPQExpBuffer(&buf,
2887 "SELECT n.nspname as \"%s\",\n"
2888 " c.relname as \"%s\",\n"
2890 " WHEN 'r' THEN '%s'"
2891 " WHEN 'v' THEN '%s'"
2892 " WHEN 'm' THEN '%s'"
2893 " WHEN 'i' THEN '%s'"
2894 " WHEN 'S' THEN '%s'"
2895 " WHEN 's' THEN '%s'"
2896 " WHEN 'f' THEN '%s'"
2898 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
2899 gettext_noop("Schema"),
2900 gettext_noop("Name"),
2901 gettext_noop("table"),
2902 gettext_noop("view"),
2903 gettext_noop("materialized view"),
2904 gettext_noop("index"),
2905 gettext_noop("sequence"),
2906 gettext_noop("special"),
2907 gettext_noop("foreign table"),
2908 gettext_noop("Type"),
2909 gettext_noop("Owner"));
2912 appendPQExpBuffer(&buf,
2913 ",\n c2.relname as \"%s\"",
2914 gettext_noop("Table"));
2919 * As of PostgreSQL 9.0, use pg_table_size() to show a more acurate
2920 * size of a table, including FSM, VM and TOAST tables.
2922 if (pset.sversion >= 90000)
2923 appendPQExpBuffer(&buf,
2924 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
2925 gettext_noop("Size"));
2926 else if (pset.sversion >= 80100)
2927 appendPQExpBuffer(&buf,
2928 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
2929 gettext_noop("Size"));
2931 appendPQExpBuffer(&buf,
2932 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
2933 gettext_noop("Description"));
2936 appendPQExpBufferStr(&buf,
2937 "\nFROM pg_catalog.pg_class c"
2938 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
2940 appendPQExpBufferStr(&buf,
2941 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
2942 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
2944 appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
2946 appendPQExpBufferStr(&buf, "'r',");
2948 appendPQExpBufferStr(&buf, "'v',");
2950 appendPQExpBufferStr(&buf, "'m',");
2952 appendPQExpBufferStr(&buf, "'i',");
2954 appendPQExpBufferStr(&buf, "'S',");
2955 if (showSystem || pattern)
2956 appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL in <=
2959 appendPQExpBufferStr(&buf, "'f',");
2961 appendPQExpBufferStr(&buf, "''"); /* dummy */
2962 appendPQExpBufferStr(&buf, ")\n");
2964 if (!showSystem && !pattern)
2965 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
2966 " AND n.nspname <> 'information_schema'\n");
2969 * TOAST objects are suppressed unconditionally. Since we don't provide
2970 * any way to select relkind 't' above, we would never show toast tables
2971 * in any case; it seems a bit confusing to allow their indexes to be
2972 * shown. Use plain \d if you really need to look at a TOAST table/index.
2974 appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
2976 processSQLNamePattern(pset.db, &buf, pattern, true, false,
2977 "n.nspname", "c.relname", NULL,
2978 "pg_catalog.pg_table_is_visible(c.oid)");
2980 appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
2982 res = PSQLexec(buf.data, false);
2983 termPQExpBuffer(&buf);
2987 if (PQntuples(res) == 0 && !pset.quiet)
2990 fprintf(pset.queryFout, _("No matching relations found.\n"));
2992 fprintf(pset.queryFout, _("No relations found.\n"));
2996 myopt.nullPrint = NULL;
2997 myopt.title = _("List of relations");
2998 myopt.translate_header = true;
2999 myopt.translate_columns = translate_columns;
3000 myopt.n_translate_columns = lengthof(translate_columns);
3002 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3013 * Describes languages.
3016 listLanguages(const char *pattern, bool verbose, bool showSystem)
3018 PQExpBufferData buf;
3020 printQueryOpt myopt = pset.popt;
3022 initPQExpBuffer(&buf);
3024 printfPQExpBuffer(&buf,
3025 "SELECT l.lanname AS \"%s\",\n",
3026 gettext_noop("Name"));
3027 if (pset.sversion >= 80300)
3028 appendPQExpBuffer(&buf,
3029 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n",
3030 gettext_noop("Owner"));
3032 appendPQExpBuffer(&buf,
3033 " l.lanpltrusted AS \"%s\"",
3034 gettext_noop("Trusted"));
3038 appendPQExpBuffer(&buf,
3039 ",\n NOT l.lanispl AS \"%s\",\n"
3040 " l.lanplcallfoid::regprocedure AS \"%s\",\n"
3041 " l.lanvalidator::regprocedure AS \"%s\",\n ",
3042 gettext_noop("Internal Language"),
3043 gettext_noop("Call Handler"),
3044 gettext_noop("Validator"));
3045 if (pset.sversion >= 90000)
3046 appendPQExpBuffer(&buf, "l.laninline::regprocedure AS \"%s\",\n ",
3047 gettext_noop("Inline Handler"));
3048 printACLColumn(&buf, "l.lanacl");
3051 appendPQExpBuffer(&buf,
3052 ",\n d.description AS \"%s\""
3053 "\nFROM pg_catalog.pg_language l\n"
3054 "LEFT JOIN pg_catalog.pg_description d\n"
3055 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
3056 " AND d.objsubid = 0\n",
3057 gettext_noop("Description"));
3060 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3061 NULL, "l.lanname", NULL, NULL);
3063 if (!showSystem && !pattern)
3064 appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
3067 appendPQExpBufferStr(&buf, "ORDER BY 1;");
3069 res = PSQLexec(buf.data, false);
3070 termPQExpBuffer(&buf);
3074 myopt.nullPrint = NULL;
3075 myopt.title = _("List of languages");
3076 myopt.translate_header = true;
3078 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3088 * Describes domains.
3091 listDomains(const char *pattern, bool verbose, bool showSystem)
3093 PQExpBufferData buf;
3095 printQueryOpt myopt = pset.popt;
3097 initPQExpBuffer(&buf);
3099 printfPQExpBuffer(&buf,
3100 "SELECT n.nspname as \"%s\",\n"
3101 " t.typname as \"%s\",\n"
3102 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
3104 gettext_noop("Schema"),
3105 gettext_noop("Name"),
3106 gettext_noop("Type"));
3108 if (pset.sversion >= 90100)
3109 appendPQExpBufferStr(&buf,
3110 " COALESCE((SELECT ' collate ' || c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
3111 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation), '') ||\n");
3112 appendPQExpBuffer(&buf,
3113 " CASE WHEN t.typnotnull THEN ' not null' ELSE '' END ||\n"
3114 " CASE WHEN t.typdefault IS NOT NULL THEN ' default ' || t.typdefault ELSE '' END\n"
3116 " pg_catalog.array_to_string(ARRAY(\n"
3117 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
3118 " ), ' ') as \"%s\"",
3119 gettext_noop("Modifier"),
3120 gettext_noop("Check"));
3124 if (pset.sversion >= 90200)
3126 appendPQExpBufferStr(&buf, ",\n ");
3127 printACLColumn(&buf, "t.typacl");
3129 appendPQExpBuffer(&buf,
3130 ",\n d.description as \"%s\"",
3131 gettext_noop("Description"));
3134 appendPQExpBufferStr(&buf,
3135 "\nFROM pg_catalog.pg_type t\n"
3136 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
3139 appendPQExpBufferStr(&buf,
3140 " LEFT JOIN pg_catalog.pg_description d "
3141 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
3142 "AND d.objsubid = 0\n");
3144 appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
3146 if (!showSystem && !pattern)
3147 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3148 " AND n.nspname <> 'information_schema'\n");
3150 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3151 "n.nspname", "t.typname", NULL,
3152 "pg_catalog.pg_type_is_visible(t.oid)");
3154 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3156 res = PSQLexec(buf.data, false);
3157 termPQExpBuffer(&buf);
3161 myopt.nullPrint = NULL;
3162 myopt.title = _("List of domains");
3163 myopt.translate_header = true;
3165 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3174 * Describes conversions.
3177 listConversions(const char *pattern, bool verbose, bool showSystem)
3179 PQExpBufferData buf;
3181 printQueryOpt myopt = pset.popt;
3182 static const bool translate_columns[] =
3183 {false, false, false, false, true, false};
3185 initPQExpBuffer(&buf);
3187 printfPQExpBuffer(&buf,
3188 "SELECT n.nspname AS \"%s\",\n"
3189 " c.conname AS \"%s\",\n"
3190 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
3191 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
3192 " CASE WHEN c.condefault THEN '%s'\n"
3193 " ELSE '%s' END AS \"%s\"",
3194 gettext_noop("Schema"),
3195 gettext_noop("Name"),
3196 gettext_noop("Source"),
3197 gettext_noop("Destination"),
3198 gettext_noop("yes"), gettext_noop("no"),
3199 gettext_noop("Default?"));
3202 appendPQExpBuffer(&buf,
3203 ",\n d.description AS \"%s\"",
3204 gettext_noop("Description"));
3206 appendPQExpBufferStr(&buf,
3207 "\nFROM pg_catalog.pg_conversion c\n"
3208 " JOIN pg_catalog.pg_namespace n "
3209 "ON n.oid = c.connamespace\n");
3212 appendPQExpBufferStr(&buf,
3213 "LEFT JOIN pg_catalog.pg_description d "
3214 "ON d.classoid = c.tableoid\n"
3215 " AND d.objoid = c.oid "
3216 "AND d.objsubid = 0\n");
3218 appendPQExpBufferStr(&buf, "WHERE true\n");
3220 if (!showSystem && !pattern)
3221 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3222 " AND n.nspname <> 'information_schema'\n");
3224 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3225 "n.nspname", "c.conname", NULL,
3226 "pg_catalog.pg_conversion_is_visible(c.oid)");
3228 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3230 res = PSQLexec(buf.data, false);
3231 termPQExpBuffer(&buf);
3235 myopt.nullPrint = NULL;
3236 myopt.title = _("List of conversions");
3237 myopt.translate_header = true;
3238 myopt.translate_columns = translate_columns;
3239 myopt.n_translate_columns = lengthof(translate_columns);
3241 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3250 * Describes Event Triggers.
3253 listEventTriggers(const char *pattern, bool verbose)
3255 PQExpBufferData buf;
3257 printQueryOpt myopt = pset.popt;
3258 static const bool translate_columns[] =
3259 {false, false, false, true, false, false, false};
3261 initPQExpBuffer(&buf);
3263 printfPQExpBuffer(&buf,
3264 "SELECT evtname as \"%s\", "
3265 "evtevent as \"%s\", "
3266 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
3267 " case evtenabled when 'O' then '%s'"
3268 " when 'R' then '%s'"
3269 " when 'A' then '%s'"
3270 " when 'D' then '%s' end as \"%s\",\n"
3271 " e.evtfoid::pg_catalog.regproc as \"%s\", "
3272 "pg_catalog.array_to_string(array(select x"
3273 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
3274 gettext_noop("Name"),
3275 gettext_noop("Event"),
3276 gettext_noop("Owner"),
3277 gettext_noop("enabled"),
3278 gettext_noop("replica"),
3279 gettext_noop("always"),
3280 gettext_noop("disabled"),
3281 gettext_noop("Enabled"),
3282 gettext_noop("Procedure"),
3283 gettext_noop("Tags"));
3285 appendPQExpBuffer(&buf,
3286 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
3287 gettext_noop("Description"));
3288 appendPQExpBufferStr(&buf,
3289 "\nFROM pg_catalog.pg_event_trigger e ");
3291 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3292 NULL, "evtname", NULL, NULL);
3294 appendPQExpBufferStr(&buf, "ORDER BY 1");
3296 res = PSQLexec(buf.data, false);
3297 termPQExpBuffer(&buf);
3301 myopt.nullPrint = NULL;
3302 myopt.title = _("List of event triggers");
3303 myopt.translate_header = true;
3304 myopt.translate_columns = translate_columns;
3305 myopt.n_translate_columns = lengthof(translate_columns);
3307 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3319 listCasts(const char *pattern, bool verbose)
3321 PQExpBufferData buf;
3323 printQueryOpt myopt = pset.popt;
3324 static const bool translate_columns[] = {false, false, false, true, false};
3326 initPQExpBuffer(&buf);
3329 * We need a left join to pg_proc for binary casts; the others are just
3330 * paranoia. Also note that we don't attempt to localize '(binary
3331 * coercible)', because there's too much risk of gettext translating a
3332 * function name that happens to match some string in the PO database.
3334 printfPQExpBuffer(&buf,
3335 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3336 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3337 " CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3340 " CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3341 " WHEN c.castcontext = 'a' THEN '%s'\n"
3344 gettext_noop("Source type"),
3345 gettext_noop("Target type"),
3346 gettext_noop("Function"),
3348 gettext_noop("in assignment"),
3349 gettext_noop("yes"),
3350 gettext_noop("Implicit?"));
3353 appendPQExpBuffer(&buf,
3354 ",\n d.description AS \"%s\"\n",
3355 gettext_noop("Description"));
3357 appendPQExpBufferStr(&buf,
3358 "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
3359 " ON c.castfunc = p.oid\n"
3360 " LEFT JOIN pg_catalog.pg_type ts\n"
3361 " ON c.castsource = ts.oid\n"
3362 " LEFT JOIN pg_catalog.pg_namespace ns\n"
3363 " ON ns.oid = ts.typnamespace\n"
3364 " LEFT JOIN pg_catalog.pg_type tt\n"
3365 " ON c.casttarget = tt.oid\n"
3366 " LEFT JOIN pg_catalog.pg_namespace nt\n"
3367 " ON nt.oid = tt.typnamespace\n");
3370 appendPQExpBufferStr(&buf,
3371 " LEFT JOIN pg_catalog.pg_description d\n"
3372 " ON d.classoid = c.tableoid AND d.objoid = "
3373 "c.oid AND d.objsubid = 0\n");
3375 appendPQExpBufferStr(&buf, "WHERE ( (true");
3378 * Match name pattern against either internal or external name of either
3379 * castsource or casttarget
3381 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3382 "ns.nspname", "ts.typname",
3383 "pg_catalog.format_type(ts.oid, NULL)",
3384 "pg_catalog.pg_type_is_visible(ts.oid)");
3386 appendPQExpBufferStr(&buf, ") OR (true");
3388 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3389 "nt.nspname", "tt.typname",
3390 "pg_catalog.format_type(tt.oid, NULL)",
3391 "pg_catalog.pg_type_is_visible(tt.oid)");
3393 appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
3395 res = PSQLexec(buf.data, false);
3396 termPQExpBuffer(&buf);
3400 myopt.nullPrint = NULL;
3401 myopt.title = _("List of casts");
3402 myopt.translate_header = true;
3403 myopt.translate_columns = translate_columns;
3404 myopt.n_translate_columns = lengthof(translate_columns);
3406 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3415 * Describes collations.
3418 listCollations(const char *pattern, bool verbose, bool showSystem)
3420 PQExpBufferData buf;
3422 printQueryOpt myopt = pset.popt;
3423 static const bool translate_columns[] = {false, false, false, false, false};
3425 if (pset.sversion < 90100)
3427 psql_error("The server (version %d.%d) does not support collations.\n",
3428 pset.sversion / 10000, (pset.sversion / 100) % 100);
3432 initPQExpBuffer(&buf);
3434 printfPQExpBuffer(&buf,
3435 "SELECT n.nspname AS \"%s\",\n"
3436 " c.collname AS \"%s\",\n"
3437 " c.collcollate AS \"%s\",\n"
3438 " c.collctype AS \"%s\"",
3439 gettext_noop("Schema"),
3440 gettext_noop("Name"),
3441 gettext_noop("Collate"),
3442 gettext_noop("Ctype"));
3445 appendPQExpBuffer(&buf,
3446 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
3447 gettext_noop("Description"));
3449 appendPQExpBufferStr(&buf,
3450 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
3451 "WHERE n.oid = c.collnamespace\n");
3453 if (!showSystem && !pattern)
3454 appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
3455 " AND n.nspname <> 'information_schema'\n");
3458 * Hide collations that aren't usable in the current database's encoding.
3459 * If you think to change this, note that pg_collation_is_visible rejects
3460 * unusable collations, so you will need to hack name pattern processing
3461 * somehow to avoid inconsistent behavior.
3463 appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
3465 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3466 "n.nspname", "c.collname", NULL,
3467 "pg_catalog.pg_collation_is_visible(c.oid)");
3469 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3471 res = PSQLexec(buf.data, false);
3472 termPQExpBuffer(&buf);
3476 myopt.nullPrint = NULL;
3477 myopt.title = _("List of collations");
3478 myopt.translate_header = true;
3479 myopt.translate_columns = translate_columns;
3480 myopt.n_translate_columns = lengthof(translate_columns);
3482 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3491 * Describes schemas (namespaces)
3494 listSchemas(const char *pattern, bool verbose, bool showSystem)
3496 PQExpBufferData buf;
3498 printQueryOpt myopt = pset.popt;
3500 initPQExpBuffer(&buf);
3501 printfPQExpBuffer(&buf,
3502 "SELECT n.nspname AS \"%s\",\n"
3503 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
3504 gettext_noop("Name"),
3505 gettext_noop("Owner"));
3509 appendPQExpBufferStr(&buf, ",\n ");
3510 printACLColumn(&buf, "n.nspacl");
3511 appendPQExpBuffer(&buf,
3512 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
3513 gettext_noop("Description"));
3516 appendPQExpBuffer(&buf,
3517 "\nFROM pg_catalog.pg_namespace n\n");
3519 if (!showSystem && !pattern)
3520 appendPQExpBufferStr(&buf,
3521 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
3523 processSQLNamePattern(pset.db, &buf, pattern,
3524 !showSystem && !pattern, false,
3525 NULL, "n.nspname", NULL,
3528 appendPQExpBufferStr(&buf, "ORDER BY 1;");
3530 res = PSQLexec(buf.data, false);
3531 termPQExpBuffer(&buf);
3535 myopt.nullPrint = NULL;
3536 myopt.title = _("List of schemas");
3537 myopt.translate_header = true;
3539 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3548 * list text search parsers
3551 listTSParsers(const char *pattern, bool verbose)
3553 PQExpBufferData buf;
3555 printQueryOpt myopt = pset.popt;
3557 if (pset.sversion < 80300)
3559 psql_error("The server (version %d.%d) does not support full text search.\n",
3560 pset.sversion / 10000, (pset.sversion / 100) % 100);
3565 return listTSParsersVerbose(pattern);
3567 initPQExpBuffer(&buf);
3569 printfPQExpBuffer(&buf,
3571 " n.nspname as \"%s\",\n"
3572 " p.prsname as \"%s\",\n"
3573 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
3574 "FROM pg_catalog.pg_ts_parser p \n"
3575 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
3576 gettext_noop("Schema"),
3577 gettext_noop("Name"),
3578 gettext_noop("Description")
3581 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3582 "n.nspname", "p.prsname", NULL,
3583 "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3585 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3587 res = PSQLexec(buf.data, false);
3588 termPQExpBuffer(&buf);
3592 myopt.nullPrint = NULL;
3593 myopt.title = _("List of text search parsers");
3594 myopt.translate_header = true;
3596 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3603 * full description of parsers
3606 listTSParsersVerbose(const char *pattern)
3608 PQExpBufferData buf;
3612 initPQExpBuffer(&buf);
3614 printfPQExpBuffer(&buf,
3618 "FROM pg_catalog.pg_ts_parser p\n"
3619 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
3622 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3623 "n.nspname", "p.prsname", NULL,
3624 "pg_catalog.pg_ts_parser_is_visible(p.oid)");
3626 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3628 res = PSQLexec(buf.data, false);
3629 termPQExpBuffer(&buf);
3633 if (PQntuples(res) == 0)
3636 psql_error("Did not find any text search parser named \"%s\".\n",
3642 for (i = 0; i < PQntuples(res); i++)
3645 const char *nspname = NULL;
3646 const char *prsname;
3648 oid = PQgetvalue(res, i, 0);
3649 if (!PQgetisnull(res, i, 1))
3650 nspname = PQgetvalue(res, i, 1);
3651 prsname = PQgetvalue(res, i, 2);
3653 if (!describeOneTSParser(oid, nspname, prsname))
3671 describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
3673 PQExpBufferData buf;
3676 printQueryOpt myopt = pset.popt;
3677 static const bool translate_columns[] = {true, false, false};
3679 initPQExpBuffer(&buf);
3681 printfPQExpBuffer(&buf,
3682 "SELECT '%s' AS \"%s\", \n"
3683 " p.prsstart::pg_catalog.regproc AS \"%s\", \n"
3684 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\" \n"
3685 " FROM pg_catalog.pg_ts_parser p \n"
3686 " WHERE p.oid = '%s' \n"
3689 " p.prstoken::pg_catalog.regproc, \n"
3690 " pg_catalog.obj_description(p.prstoken, 'pg_proc') \n"
3691 " FROM pg_catalog.pg_ts_parser p \n"
3692 " WHERE p.oid = '%s' \n"
3695 " p.prsend::pg_catalog.regproc, \n"
3696 " pg_catalog.obj_description(p.prsend, 'pg_proc') \n"
3697 " FROM pg_catalog.pg_ts_parser p \n"
3698 " WHERE p.oid = '%s' \n"
3701 " p.prsheadline::pg_catalog.regproc, \n"
3702 " pg_catalog.obj_description(p.prsheadline, 'pg_proc') \n"
3703 " FROM pg_catalog.pg_ts_parser p \n"
3704 " WHERE p.oid = '%s' \n"
3707 " p.prslextype::pg_catalog.regproc, \n"
3708 " pg_catalog.obj_description(p.prslextype, 'pg_proc') \n"
3709 " FROM pg_catalog.pg_ts_parser p \n"
3710 " WHERE p.oid = '%s';",
3711 gettext_noop("Start parse"),
3712 gettext_noop("Method"),
3713 gettext_noop("Function"),
3714 gettext_noop("Description"),
3716 gettext_noop("Get next token"),
3718 gettext_noop("End parse"),
3720 gettext_noop("Get headline"),
3722 gettext_noop("Get token types"),
3725 res = PSQLexec(buf.data, false);
3726 termPQExpBuffer(&buf);
3730 myopt.nullPrint = NULL;
3732 sprintf(title, _("Text search parser \"%s.%s\""), nspname, prsname);
3734 sprintf(title, _("Text search parser \"%s\""), prsname);
3735 myopt.title = title;
3736 myopt.footers = NULL;
3737 myopt.topt.default_footer = false;
3738 myopt.translate_header = true;
3739 myopt.translate_columns = translate_columns;
3740 myopt.n_translate_columns = lengthof(translate_columns);
3742 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3746 initPQExpBuffer(&buf);
3748 printfPQExpBuffer(&buf,
3749 "SELECT t.alias as \"%s\", \n"
3750 " t.description as \"%s\" \n"
3751 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t \n"
3753 gettext_noop("Token name"),
3754 gettext_noop("Description"),
3757 res = PSQLexec(buf.data, false);
3758 termPQExpBuffer(&buf);
3762 myopt.nullPrint = NULL;
3764 sprintf(title, _("Token types for parser \"%s.%s\""), nspname, prsname);
3766 sprintf(title, _("Token types for parser \"%s\""), prsname);
3767 myopt.title = title;
3768 myopt.footers = NULL;
3769 myopt.topt.default_footer = true;
3770 myopt.translate_header = true;
3771 myopt.translate_columns = NULL;
3772 myopt.n_translate_columns = 0;
3774 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3783 * list text search dictionaries
3786 listTSDictionaries(const char *pattern, bool verbose)
3788 PQExpBufferData buf;
3790 printQueryOpt myopt = pset.popt;
3792 if (pset.sversion < 80300)
3794 psql_error("The server (version %d.%d) does not support full text search.\n",
3795 pset.sversion / 10000, (pset.sversion / 100) % 100);
3799 initPQExpBuffer(&buf);
3801 printfPQExpBuffer(&buf,
3803 " n.nspname as \"%s\",\n"
3804 " d.dictname as \"%s\",\n",
3805 gettext_noop("Schema"),
3806 gettext_noop("Name"));
3810 appendPQExpBuffer(&buf,
3811 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM \n"
3812 " pg_catalog.pg_ts_template t \n"
3813 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace \n"
3814 " WHERE d.dicttemplate = t.oid ) AS \"%s\", \n"
3815 " d.dictinitoption as \"%s\", \n",
3816 gettext_noop("Template"),
3817 gettext_noop("Init options"));
3820 appendPQExpBuffer(&buf,
3821 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
3822 gettext_noop("Description"));
3824 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
3825 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
3827 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3828 "n.nspname", "d.dictname", NULL,
3829 "pg_catalog.pg_ts_dict_is_visible(d.oid)");
3831 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3833 res = PSQLexec(buf.data, false);
3834 termPQExpBuffer(&buf);
3838 myopt.nullPrint = NULL;
3839 myopt.title = _("List of text search dictionaries");
3840 myopt.translate_header = true;
3842 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3851 * list text search templates
3854 listTSTemplates(const char *pattern, bool verbose)
3856 PQExpBufferData buf;
3858 printQueryOpt myopt = pset.popt;
3860 if (pset.sversion < 80300)
3862 psql_error("The server (version %d.%d) does not support full text search.\n",
3863 pset.sversion / 10000, (pset.sversion / 100) % 100);
3867 initPQExpBuffer(&buf);
3870 printfPQExpBuffer(&buf,
3872 " n.nspname AS \"%s\",\n"
3873 " t.tmplname AS \"%s\",\n"
3874 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
3875 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
3876 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
3877 gettext_noop("Schema"),
3878 gettext_noop("Name"),
3879 gettext_noop("Init"),
3880 gettext_noop("Lexize"),
3881 gettext_noop("Description"));
3883 printfPQExpBuffer(&buf,
3885 " n.nspname AS \"%s\",\n"
3886 " t.tmplname AS \"%s\",\n"
3887 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
3888 gettext_noop("Schema"),
3889 gettext_noop("Name"),
3890 gettext_noop("Description"));
3892 appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
3893 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
3895 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3896 "n.nspname", "t.tmplname", NULL,
3897 "pg_catalog.pg_ts_template_is_visible(t.oid)");
3899 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3901 res = PSQLexec(buf.data, false);
3902 termPQExpBuffer(&buf);
3906 myopt.nullPrint = NULL;
3907 myopt.title = _("List of text search templates");
3908 myopt.translate_header = true;
3910 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3919 * list text search configurations
3922 listTSConfigs(const char *pattern, bool verbose)
3924 PQExpBufferData buf;
3926 printQueryOpt myopt = pset.popt;
3928 if (pset.sversion < 80300)
3930 psql_error("The server (version %d.%d) does not support full text search.\n",
3931 pset.sversion / 10000, (pset.sversion / 100) % 100);
3936 return listTSConfigsVerbose(pattern);
3938 initPQExpBuffer(&buf);
3940 printfPQExpBuffer(&buf,
3942 " n.nspname as \"%s\",\n"
3943 " c.cfgname as \"%s\",\n"
3944 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
3945 "FROM pg_catalog.pg_ts_config c\n"
3946 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace \n",
3947 gettext_noop("Schema"),
3948 gettext_noop("Name"),
3949 gettext_noop("Description")
3952 processSQLNamePattern(pset.db, &buf, pattern, false, false,
3953 "n.nspname", "c.cfgname", NULL,
3954 "pg_catalog.pg_ts_config_is_visible(c.oid)");
3956 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
3958 res = PSQLexec(buf.data, false);
3959 termPQExpBuffer(&buf);
3963 myopt.nullPrint = NULL;
3964 myopt.title = _("List of text search configurations");
3965 myopt.translate_header = true;
3967 printQuery(res, &myopt, pset.queryFout, pset.logfile);
3974 listTSConfigsVerbose(const char *pattern)
3976 PQExpBufferData buf;
3980 initPQExpBuffer(&buf);
3982 printfPQExpBuffer(&buf,
3983 "SELECT c.oid, c.cfgname,\n"
3986 " np.nspname as pnspname \n"
3987 "FROM pg_catalog.pg_ts_config c \n"
3988 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace, \n"
3989 " pg_catalog.pg_ts_parser p \n"
3990 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace \n"
3991 "WHERE p.oid = c.cfgparser\n"
3994 processSQLNamePattern(pset.db, &buf, pattern, true, false,
3995 "n.nspname", "c.cfgname", NULL,
3996 "pg_catalog.pg_ts_config_is_visible(c.oid)");
3998 appendPQExpBufferStr(&buf, "ORDER BY 3, 2;");
4000 res = PSQLexec(buf.data, false);
4001 termPQExpBuffer(&buf);
4005 if (PQntuples(res) == 0)
4008 psql_error("Did not find any text search configuration named \"%s\".\n",
4014 for (i = 0; i < PQntuples(res); i++)
4017 const char *cfgname;
4018 const char *nspname = NULL;
4019 const char *prsname;
4020 const char *pnspname = NULL;
4022 oid = PQgetvalue(res, i, 0);
4023 cfgname = PQgetvalue(res, i, 1);
4024 if (!PQgetisnull(res, i, 2))
4025 nspname = PQgetvalue(res, i, 2);
4026 prsname = PQgetvalue(res, i, 3);
4027 if (!PQgetisnull(res, i, 4))
4028 pnspname = PQgetvalue(res, i, 4);
4030 if (!describeOneTSConfig(oid, nspname, cfgname, pnspname, prsname))
4048 describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
4049 const char *pnspname, const char *prsname)
4051 PQExpBufferData buf,
4054 printQueryOpt myopt = pset.popt;
4056 initPQExpBuffer(&buf);
4058 printfPQExpBuffer(&buf,
4060 " ( SELECT t.alias FROM \n"
4061 " pg_catalog.ts_token_type(c.cfgparser) AS t \n"
4062 " WHERE t.tokid = m.maptokentype ) AS \"%s\", \n"
4063 " pg_catalog.btrim( \n"
4064 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary \n"
4065 " FROM pg_catalog.pg_ts_config_map AS mm \n"
4066 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype \n"
4067 " ORDER BY mapcfg, maptokentype, mapseqno \n"
4068 " ) :: pg_catalog.text , \n"
4069 " '{}') AS \"%s\" \n"
4070 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m \n"
4071 "WHERE c.oid = '%s' AND m.mapcfg = c.oid \n"
4072 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser \n"
4074 gettext_noop("Token"),
4075 gettext_noop("Dictionaries"),
4078 res = PSQLexec(buf.data, false);
4079 termPQExpBuffer(&buf);
4083 initPQExpBuffer(&title);
4086 appendPQExpBuffer(&title, _("Text search configuration \"%s.%s\""),
4089 appendPQExpBuffer(&title, _("Text search configuration \"%s\""),
4093 appendPQExpBuffer(&title, _("\nParser: \"%s.%s\""),
4096 appendPQExpBuffer(&title, _("\nParser: \"%s\""),
4099 myopt.nullPrint = NULL;
4100 myopt.title = title.data;
4101 myopt.footers = NULL;
4102 myopt.topt.default_footer = false;
4103 myopt.translate_header = true;
4105 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4107 termPQExpBuffer(&title);
4117 * Describes foreign-data wrappers
4120 listForeignDataWrappers(const char *pattern, bool verbose)
4122 PQExpBufferData buf;
4124 printQueryOpt myopt = pset.popt;
4126 if (pset.sversion < 80400)
4128 psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
4129 pset.sversion / 10000, (pset.sversion / 100) % 100);
4133 initPQExpBuffer(&buf);
4134 printfPQExpBuffer(&buf,
4135 "SELECT fdw.fdwname AS \"%s\",\n"
4136 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n",
4137 gettext_noop("Name"),
4138 gettext_noop("Owner"));
4139 if (pset.sversion >= 90100)
4140 appendPQExpBuffer(&buf,
4141 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n",
4142 gettext_noop("Handler"));
4143 appendPQExpBuffer(&buf,
4144 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
4145 gettext_noop("Validator"));
4149 appendPQExpBufferStr(&buf, ",\n ");
4150 printACLColumn(&buf, "fdwacl");
4151 appendPQExpBuffer(&buf,
4152 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
4153 " '(' || array_to_string(ARRAY(SELECT "
4154 " quote_ident(option_name) || ' ' || "
4155 " quote_literal(option_value) FROM "
4156 " pg_options_to_table(fdwoptions)), ', ') || ')' "
4158 gettext_noop("FDW Options"));
4160 if (pset.sversion >= 90100)
4161 appendPQExpBuffer(&buf,
4162 ",\n d.description AS \"%s\" ",
4163 gettext_noop("Description"));
4166 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
4168 if (verbose && pset.sversion >= 90100)
4169 appendPQExpBufferStr(&buf,
4170 "LEFT JOIN pg_catalog.pg_description d\n"
4171 " ON d.classoid = fdw.tableoid "
4172 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
4174 processSQLNamePattern(pset.db, &buf, pattern, false, false,
4175 NULL, "fdwname", NULL, NULL);
4177 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4179 res = PSQLexec(buf.data, false);
4180 termPQExpBuffer(&buf);
4184 myopt.nullPrint = NULL;
4185 myopt.title = _("List of foreign-data wrappers");
4186 myopt.translate_header = true;
4188 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4197 * Describes foreign servers.
4200 listForeignServers(const char *pattern, bool verbose)
4202 PQExpBufferData buf;
4204 printQueryOpt myopt = pset.popt;
4206 if (pset.sversion < 80400)
4208 psql_error("The server (version %d.%d) does not support foreign servers.\n",
4209 pset.sversion / 10000, (pset.sversion / 100) % 100);
4213 initPQExpBuffer(&buf);
4214 printfPQExpBuffer(&buf,
4215 "SELECT s.srvname AS \"%s\",\n"
4216 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
4217 " f.fdwname AS \"%s\"",
4218 gettext_noop("Name"),
4219 gettext_noop("Owner"),
4220 gettext_noop("Foreign-data wrapper"));
4224 appendPQExpBufferStr(&buf, ",\n ");
4225 printACLColumn(&buf, "s.srvacl");
4226 appendPQExpBuffer(&buf,
4228 " s.srvtype AS \"%s\",\n"
4229 " s.srvversion AS \"%s\",\n"
4230 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
4231 " '(' || array_to_string(ARRAY(SELECT "
4232 " quote_ident(option_name) || ' ' || "
4233 " quote_literal(option_value) FROM "
4234 " pg_options_to_table(srvoptions)), ', ') || ')' "
4236 " d.description AS \"%s\"",
4237 gettext_noop("Type"),
4238 gettext_noop("Version"),
4239 gettext_noop("FDW Options"),
4240 gettext_noop("Description"));
4243 appendPQExpBufferStr(&buf,
4244 "\nFROM pg_catalog.pg_foreign_server s\n"
4245 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
4248 appendPQExpBufferStr(&buf,
4249 "LEFT JOIN pg_description d\n "
4250 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
4251 "AND d.objsubid = 0\n");
4253 processSQLNamePattern(pset.db, &buf, pattern, false, false,
4254 NULL, "s.srvname", NULL, NULL);
4256 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4258 res = PSQLexec(buf.data, false);
4259 termPQExpBuffer(&buf);
4263 myopt.nullPrint = NULL;
4264 myopt.title = _("List of foreign servers");
4265 myopt.translate_header = true;
4267 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4276 * Describes user mappings.
4279 listUserMappings(const char *pattern, bool verbose)
4281 PQExpBufferData buf;
4283 printQueryOpt myopt = pset.popt;
4285 if (pset.sversion < 80400)
4287 psql_error("The server (version %d.%d) does not support user mappings.\n",
4288 pset.sversion / 10000, (pset.sversion / 100) % 100);
4292 initPQExpBuffer(&buf);
4293 printfPQExpBuffer(&buf,
4294 "SELECT um.srvname AS \"%s\",\n"
4295 " um.usename AS \"%s\"",
4296 gettext_noop("Server"),
4297 gettext_noop("User name"));
4300 appendPQExpBuffer(&buf,
4301 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
4302 " '(' || array_to_string(ARRAY(SELECT "
4303 " quote_ident(option_name) || ' ' || "
4304 " quote_literal(option_value) FROM "
4305 " pg_options_to_table(umoptions)), ', ') || ')' "
4307 gettext_noop("FDW Options"));
4309 appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
4311 processSQLNamePattern(pset.db, &buf, pattern, false, false,
4312 NULL, "um.srvname", "um.usename", NULL);
4314 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4316 res = PSQLexec(buf.data, false);
4317 termPQExpBuffer(&buf);
4321 myopt.nullPrint = NULL;
4322 myopt.title = _("List of user mappings");
4323 myopt.translate_header = true;
4325 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4334 * Describes foreign tables.
4337 listForeignTables(const char *pattern, bool verbose)
4339 PQExpBufferData buf;
4341 printQueryOpt myopt = pset.popt;
4343 if (pset.sversion < 90100)
4345 psql_error("The server (version %d.%d) does not support foreign tables.\n",
4346 pset.sversion / 10000, (pset.sversion / 100) % 100);
4350 initPQExpBuffer(&buf);
4351 printfPQExpBuffer(&buf,
4352 "SELECT n.nspname AS \"%s\",\n"
4353 " c.relname AS \"%s\",\n"
4354 " s.srvname AS \"%s\"",
4355 gettext_noop("Schema"),
4356 gettext_noop("Table"),
4357 gettext_noop("Server"));
4360 appendPQExpBuffer(&buf,
4361 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
4362 " '(' || array_to_string(ARRAY(SELECT "
4363 " quote_ident(option_name) || ' ' || "
4364 " quote_literal(option_value) FROM "
4365 " pg_options_to_table(ftoptions)), ', ') || ')' "
4367 " d.description AS \"%s\"",
4368 gettext_noop("FDW Options"),
4369 gettext_noop("Description"));
4371 appendPQExpBufferStr(&buf,
4372 "\nFROM pg_catalog.pg_foreign_table ft\n"
4373 " INNER JOIN pg_catalog.pg_class c"
4374 " ON c.oid = ft.ftrelid\n"
4375 " INNER JOIN pg_catalog.pg_namespace n"
4376 " ON n.oid = c.relnamespace\n"
4377 " INNER JOIN pg_catalog.pg_foreign_server s"
4378 " ON s.oid = ft.ftserver\n");
4380 appendPQExpBufferStr(&buf,
4381 " LEFT JOIN pg_catalog.pg_description d\n"
4382 " ON d.classoid = c.tableoid AND "
4383 "d.objoid = c.oid AND d.objsubid = 0\n");
4385 processSQLNamePattern(pset.db, &buf, pattern, false, false,
4386 NULL, "n.nspname", "c.relname", NULL);
4388 appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
4390 res = PSQLexec(buf.data, false);
4391 termPQExpBuffer(&buf);
4395 myopt.nullPrint = NULL;
4396 myopt.title = _("List of foreign tables");
4397 myopt.translate_header = true;
4399 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4408 * Briefly describes installed extensions.
4411 listExtensions(const char *pattern)
4413 PQExpBufferData buf;
4415 printQueryOpt myopt = pset.popt;
4417 if (pset.sversion < 90100)
4419 psql_error("The server (version %d.%d) does not support extensions.\n",
4420 pset.sversion / 10000, (pset.sversion / 100) % 100);
4424 initPQExpBuffer(&buf);
4425 printfPQExpBuffer(&buf,
4426 "SELECT e.extname AS \"%s\", "
4427 "e.extversion AS \"%s\", n.nspname AS \"%s\", c.description AS \"%s\"\n"
4428 "FROM pg_catalog.pg_extension e "
4429 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
4430 "LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid "
4431 "AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
4432 gettext_noop("Name"),
4433 gettext_noop("Version"),
4434 gettext_noop("Schema"),
4435 gettext_noop("Description"));
4437 processSQLNamePattern(pset.db, &buf, pattern,
4439 NULL, "e.extname", NULL,
4442 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4444 res = PSQLexec(buf.data, false);
4445 termPQExpBuffer(&buf);
4449 myopt.nullPrint = NULL;
4450 myopt.title = _("List of installed extensions");
4451 myopt.translate_header = true;
4453 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4462 * List contents of installed extensions.
4465 listExtensionContents(const char *pattern)
4467 PQExpBufferData buf;
4471 if (pset.sversion < 90100)
4473 psql_error("The server (version %d.%d) does not support extensions.\n",
4474 pset.sversion / 10000, (pset.sversion / 100) % 100);
4478 initPQExpBuffer(&buf);
4479 printfPQExpBuffer(&buf,
4480 "SELECT e.extname, e.oid\n"
4481 "FROM pg_catalog.pg_extension e\n");
4483 processSQLNamePattern(pset.db, &buf, pattern,
4485 NULL, "e.extname", NULL,
4488 appendPQExpBufferStr(&buf, "ORDER BY 1;");
4490 res = PSQLexec(buf.data, false);
4491 termPQExpBuffer(&buf);
4495 if (PQntuples(res) == 0)
4500 psql_error("Did not find any extension named \"%s\".\n",
4503 psql_error("Did not find any extensions.\n");
4509 for (i = 0; i < PQntuples(res); i++)
4511 const char *extname;
4514 extname = PQgetvalue(res, i, 0);
4515 oid = PQgetvalue(res, i, 1);
4517 if (!listOneExtensionContents(extname, oid))
4534 listOneExtensionContents(const char *extname, const char *oid)
4536 PQExpBufferData buf;
4539 printQueryOpt myopt = pset.popt;
4541 initPQExpBuffer(&buf);
4542 printfPQExpBuffer(&buf,
4543 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
4544 "FROM pg_catalog.pg_depend\n"
4545 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
4547 gettext_noop("Object Description"),
4550 res = PSQLexec(buf.data, false);
4551 termPQExpBuffer(&buf);
4555 myopt.nullPrint = NULL;
4556 snprintf(title, sizeof(title), _("Objects in extension \"%s\""), extname);
4557 myopt.title = title;
4558 myopt.translate_header = true;
4560 printQuery(res, &myopt, pset.queryFout, pset.logfile);
4569 * Helper function for consistently formatting ACL (privilege) columns.
4570 * The proper targetlist entry is appended to buf. Note lack of any
4571 * whitespace or comma decoration.
4574 printACLColumn(PQExpBuffer buf, const char *colname)
4576 if (pset.sversion >= 80100)
4577 appendPQExpBuffer(buf,
4578 "pg_catalog.array_to_string(%s, E'\\n') AS \"%s\"",
4579 colname, gettext_noop("Access privileges"));
4581 appendPQExpBuffer(buf,
4582 "pg_catalog.array_to_string(%s, '\\n') AS \"%s\"",
4583 colname, gettext_noop("Access privileges"));