summaryrefslogtreecommitdiff
path: root/src/bin/psql/describe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/describe.c')
-rw-r--r--src/bin/psql/describe.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 0342eb55bdc..884101aab18 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -627,7 +627,7 @@ listAllDbs(bool verbose)
appendPQExpBuffer(&buf,
" d.datcollate as \"%s\",\n"
" d.datctype as \"%s\",\n",
- gettext_noop("Collation"),
+ gettext_noop("Collate"),
gettext_noop("Ctype"));
appendPQExpBuffer(&buf, " ");
printACLColumn(&buf, "d.datacl");
@@ -2857,6 +2857,66 @@ listCasts(const char *pattern)
}
/*
+ * \dO
+ *
+ * Describes collations
+ */
+bool
+listCollations(const char *pattern, bool verbose, bool showSystem)
+{
+ PQExpBufferData buf;
+ PGresult *res;
+ printQueryOpt myopt = pset.popt;
+ static const bool translate_columns[] = {false, false, false, false, false};
+
+ initPQExpBuffer(&buf);
+
+ printfPQExpBuffer(&buf,
+ "SELECT n.nspname AS \"%s\",\n"
+ " c.collname AS \"%s\",\n"
+ " c.collcollate AS \"%s\",\n"
+ " c.collctype AS \"%s\"",
+ gettext_noop("Schema"),
+ gettext_noop("Name"),
+ gettext_noop("Collate"),
+ gettext_noop("Ctype"));
+
+ if (verbose)
+ appendPQExpBuffer(&buf,
+ ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
+ gettext_noop("Description"));
+
+ appendPQExpBuffer(&buf,
+ "FROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
+ "WHERE n.oid = c.collnamespace\n");
+
+ if (!showSystem && !pattern)
+ appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n"
+ " AND n.nspname <> 'information_schema'\n");
+
+ processSQLNamePattern(pset.db, &buf, pattern, true, false,
+ "n.nspname", "c.collname", NULL,
+ "pg_catalog.pg_collation_is_visible(c.oid)");
+
+ appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
+
+ res = PSQLexec(buf.data, false);
+ termPQExpBuffer(&buf);
+ if (!res)
+ return false;
+
+ myopt.nullPrint = NULL;
+ myopt.title = _("List of collations");
+ myopt.translate_header = true;
+ myopt.translate_columns = translate_columns;
+
+ printQuery(res, &myopt, pset.queryFout, pset.logfile);
+
+ PQclear(res);
+ return true;
+}
+
+/*
* \dn
*
* Describes schemas (namespaces)