Here is a diff of changes to the psql source code implementing a simple
authorBruce Momjian <bruce@momjian.us>
Wed, 6 Mar 2002 20:39:45 +0000 (20:39 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 6 Mar 2002 20:39:45 +0000 (20:39 +0000)
'list domains' command '\dD'. This is the interface component of
rbt@zort.ca's domain backend modifications.

Jonathan Eisler

src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h
src/bin/psql/help.c

index 398ac00b8ac2d54ad38cce764a225380631969ef..b9388b5816fc62d5b6ebf2382f11d7b1f8d82373 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.67 2002/03/05 00:01:00 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.68 2002/03/06 20:39:45 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -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 ef31c5ee906b5489fa2a5bedaa92712b10afd16c..823755ccd26e9f44a053954124d0a354f5aec68f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.43 2002/03/05 02:42:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.44 2002/03/06 20:39:45 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -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 88c1b6df49a84008fec8d0752f6a62e51ef157fd..830612ee2273bad326b9e891020a124c2dac299c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.13 2001/11/05 17:46:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.14 2002/03/06 20:39:45 momjian Exp $
  */
 #ifndef DESCRIBE_H
 #define DESCRIBE_H
@@ -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 34bcc8152eac77194b4729237c0571c87ae3fdb3..bccef415e196fdfdcccd86a229019a7c046b24d7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.44 2002/03/05 06:13:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.45 2002/03/06 20:39:45 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "help.h"
@@ -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"));