diff options
| author | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:39:45 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:39:45 +0000 |
| commit | c666d6fd41d654967d89eb3316e8d4cc0a924fa1 (patch) | |
| tree | 97e100eef7cf6068cb0dc691ee7abe6bab6b00bd /src/bin/psql/describe.c | |
| parent | 01c76f7411c24b11e4ab36a9fe5f5017dc33be78 (diff) | |
| download | postgresql-c666d6fd41d654967d89eb3316e8d4cc0a924fa1.tar.gz | |
Here is a diff of changes to the psql source code implementing a simple
'list domains' command '\dD'. This is the interface component of
rbt@zort.ca's domain backend modifications.
Jonathan Eisler
Diffstat (limited to 'src/bin/psql/describe.c')
| -rw-r--r-- | src/bin/psql/describe.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ef31c5ee90..823755ccd2 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -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; +} |
