|
3 | 3 | *
|
4 | 4 | * Copyright 2000 by PostgreSQL Global Development Group
|
5 | 5 | *
|
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 $ |
7 | 7 | */
|
8 | 8 | #include "postgres_fe.h"
|
9 | 9 | #include "describe.h"
|
@@ -1036,3 +1036,51 @@ listTables(const char *infotype, const char *name, bool desc)
|
1036 | 1036 | PQclear(res);
|
1037 | 1037 | return true;
|
1038 | 1038 | }
|
| 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 | +} |
0 commit comments