Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a7ade2b

Browse files
committed
Add psql \dD listing of domains, from Jonathan Eisler.
1 parent d3788c3 commit a7ade2b

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.63 2002/03/11 05:03:52 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.64 2002/03/19 02:32:19 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -415,6 +415,29 @@ testdb=>
415415
</varlistentry>
416416

417417

418+
<varlistentry>
419+
<term><literal>\dD</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
420+
<listitem>
421+
<para>
422+
Lists all database domains.
423+
</para>
424+
425+
<para>
426+
Descriptions for objects can be generated with the <command>COMMENT ON</command>
427+
<acronym>SQL</acronym> command.
428+
</para>
429+
430+
<note>
431+
<para>
432+
<productname>PostgreSQL</productname> stores the object descriptions in the
433+
pg_description system table.
434+
</para>
435+
</note>
436+
437+
</listitem>
438+
</varlistentry>
439+
440+
418441
<varlistentry>
419442
<term><literal>\df [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
420443

src/bin/psql/command.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.69 2002/03/07 17:54:39 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.70 2002/03/19 02:32:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -380,6 +380,10 @@ exec_command(const char *cmd,
380380
case 'u':
381381
success = describeUsers(name);
382382
break;
383+
case 'D':
384+
success = listDomains(name);
385+
break;
386+
383387
default:
384388
status = CMD_UNKNOWN;
385389
}

src/bin/psql/describe.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.45 2002/03/07 17:54:39 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.46 2002/03/19 02:32:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -1036,3 +1036,51 @@ listTables(const char *infotype, const char *name, bool desc)
10361036
PQclear(res);
10371037
return true;
10381038
}
1039+
1040+
/*
1041+
* \dD [domain]
1042+
*
1043+
* Describes domains, possibly based on a simplistic prefix search on the
1044+
* argument.
1045+
*/
1046+
1047+
bool
1048+
listDomains(const char *name)
1049+
{
1050+
char buf[512 + REGEXP_CUTOFF];
1051+
PGresult *res;
1052+
printQueryOpt myopt = pset.popt;
1053+
1054+
snprintf(buf, sizeof(buf),
1055+
"SELECT t.typname as \"%s\",\n"
1056+
" format_type( t.typbasetype, t.typmod) as \"%s\",\n"
1057+
" CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
1058+
" WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
1059+
" WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
1060+
" ELSE ''\n"
1061+
" END as \"%s\"\n"
1062+
"FROM pg_type t\n"
1063+
"WHERE t.typtype = 'd'\n",
1064+
_("Name"),
1065+
_("Type"),
1066+
_("Modifier"));
1067+
if (name)
1068+
{
1069+
strcat(buf, "AND t.typname ~ '^");
1070+
strncat(buf, name, REGEXP_CUTOFF);
1071+
strcat(buf, "'\n");
1072+
}
1073+
strcat(buf, "ORDER BY 1;");
1074+
1075+
res = PSQLexec(buf);
1076+
if (!res)
1077+
return false;
1078+
1079+
myopt.nullPrint = NULL;
1080+
myopt.title = _("List of database domains");
1081+
1082+
printQuery(res, &myopt, pset.queryFout);
1083+
1084+
PQclear(res);
1085+
return true;
1086+
}

src/bin/psql/describe.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.15 2002/03/07 17:54:41 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.16 2002/03/19 02:32:21 momjian Exp $
77
*/
88
#ifndef DESCRIBE_H
99
#define DESCRIBE_H
@@ -40,4 +40,7 @@ bool listAllDbs(bool desc);
4040
/* \dt, \di, \ds, \dS, etc. */
4141
bool listTables(const char *infotype, const char *name, bool desc);
4242

43+
/* \dD */
44+
bool listDomains(const char *name);
45+
4346
#endif /* DESCRIBE_H */

src/bin/psql/help.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.48 2002/03/11 18:26:20 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.49 2002/03/19 02:32:21 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "help.h"
@@ -202,6 +202,7 @@ slashUsage(void)
202202
fprintf(fout, _(" \\d{p|S|l} list access privileges, system tables, or large objects\n"));
203203
fprintf(fout, _(" \\da list aggregate functions\n"));
204204
fprintf(fout, _(" \\dd [NAME] show comment for table, type, function, or operator\n"));
205+
fprintf(fout, _(" \\dD [NAME] list domains\n"));
205206
fprintf(fout, _(" \\df list functions\n"));
206207
fprintf(fout, _(" \\do list operators\n"));
207208
fprintf(fout, _(" \\dT list data types\n"));

0 commit comments

Comments
 (0)