Add psql \dD listing of domains, from Jonathan Eisler.
authorBruce Momjian <bruce@momjian.us>
Tue, 19 Mar 2002 02:32:21 +0000 (02:32 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 19 Mar 2002 02:32:21 +0000 (02:32 +0000)
doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h
src/bin/psql/help.c

index 6536f1a0724199ef122a42765cf152d2abe04cf8..212195e70d56ca90f6e67a71f73b958dc5cbddf6 100644 (file)
@@ -415,6 +415,29 @@ testdb=>
       </varlistentry>
 
 
+      <varlistentry>
+        <term><literal>\dD</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
+        <listitem>
+        <para>
+        Lists all database domains.
+        </para>
+
+        <para>
+        Descriptions for objects can be generated with the <command>COMMENT ON</command>
+        <acronym>SQL</acronym> command.
+       </para>
+
+        <note>
+        <para>
+        <productname>PostgreSQL</productname> stores the object descriptions in the
+        pg_description system table.
+        </para>
+        </note>
+
+        </listitem>
+      </varlistentry>
+
+
       <varlistentry>
         <term><literal>\df [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
 
index 90da4ee91c603437753e07d10319dc224e27685c..a1ca03df5511acbbf797af9d8f38bece2e98047f 100644 (file)
@@ -380,6 +380,10 @@ exec_command(const char *cmd,
                        case 'u':
                                success = describeUsers(name);
                                break;
+                       case 'D':
+                               success = listDomains(name);
+                               break;
+
                        default:
                                status = CMD_UNKNOWN;
                }
index a98de98afc01af5deb8760774f07ebced7f473a2..74d41a371ba732c578238def2fb30abc5dce35df 100644 (file)
@@ -1036,3 +1036,51 @@ listTables(const char *infotype, const char *name, bool desc)
        PQclear(res);
        return true;
 }
+
+/*
+ * \dD [domain]
+ *
+ * Describes domains, possibly based on a simplistic prefix search on the
+ * argument.
+ */
+
+bool
+listDomains(const char *name)
+{
+       char            buf[512 + REGEXP_CUTOFF];
+       PGresult   *res;
+       printQueryOpt myopt = pset.popt;
+
+       snprintf(buf, sizeof(buf),
+                "SELECT t.typname as \"%s\",\n"
+                "       format_type( t.typbasetype, t.typmod) as \"%s\",\n"
+                "       CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
+                "            WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
+                "            WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
+                "            ELSE ''\n"
+                "       END as \"%s\"\n"
+                "FROM pg_type t\n"
+                "WHERE t.typtype = 'd'\n",
+                _("Name"),
+                _("Type"),
+                _("Modifier"));
+       if (name)
+       {
+               strcat(buf, "AND t.typname ~ '^");
+               strncat(buf, name, REGEXP_CUTOFF);
+               strcat(buf, "'\n");
+       }
+       strcat(buf, "ORDER BY 1;");
+
+       res = PSQLexec(buf);
+       if (!res)
+               return false;
+
+       myopt.nullPrint = NULL;
+       myopt.title = _("List of database domains");
+
+       printQuery(res, &myopt, pset.queryFout);
+
+       PQclear(res);
+       return true;
+}
index 943a4ce2d54df699fb834909d4d86ee88348ba30..8adbd3b72e6073049a22325fb26f5b0eb5fe41d3 100644 (file)
@@ -40,4 +40,7 @@ bool          listAllDbs(bool desc);
 /* \dt, \di, \ds, \dS, etc. */
 bool           listTables(const char *infotype, const char *name, bool desc);
 
+/* \dD */
+bool           listDomains(const char *name);
+
 #endif   /* DESCRIBE_H */
index a99c4013879be2c3c11b702fba3e6573c736b4b8..8d3a50db1f063196ffb1b80eebddc40f7a6b752d 100644 (file)
@@ -202,6 +202,7 @@ slashUsage(void)
        fprintf(fout, _(" \\d{p|S|l}      list access privileges, system tables, or large objects\n"));
        fprintf(fout, _(" \\da            list aggregate functions\n"));
        fprintf(fout, _(" \\dd [NAME]     show comment for table, type, function, or operator\n"));
+       fprintf(fout, _(" \\dD [NAME]     list domains\n"));
        fprintf(fout, _(" \\df            list functions\n"));
        fprintf(fout, _(" \\do            list operators\n"));
        fprintf(fout, _(" \\dT            list data types\n"));