summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-02-26 18:31:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-02-26 18:31:25 +0000
commitcbf4c9671ed01c769c6d6abb29fe082437373c33 (patch)
treec4f0dad48e450284b7d921f724b8e268ade4ceb0 /src
parent6f11af0c62ac66e0878bd0a6eae637c427355c69 (diff)
psql's \d command wasn't doing the right things with 'char' (type 18)
fields, nor with bpchar and varchar fields that have typmod -1. The latter effectively have an unspecified length, so I made them display as char() and varchar() rather than falsely equating them to char(1) and varchar(1).
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/describe.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 0282906064c..631a04b336d 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.17 2000/02/16 13:15:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.18 2000/02/26 18:31:25 tgl Exp $
*/
#include "postgres.h"
#include "describe.h"
@@ -631,9 +631,7 @@ describeTableDetails(const char *name, bool desc)
attype++;
}
/* (convert some internal type names to SQL'ish) */
- if (strcmp(attype, "bpchar")==0)
- typename = "char";
- else if (strcmp(attype, "int2")==0)
+ if (strcmp(attype, "int2")==0)
typename = "smallint";
else if (strcmp(attype, "int4")==0)
typename = "integer";
@@ -646,13 +644,26 @@ describeTableDetails(const char *name, bool desc)
/* more might need to be added when date/time types are sorted out */
cells[i * cols + 1] = xmalloc(NAMEDATALEN + 16);
- if (strcmp(typename, "char") == 0)
- sprintf(cells[i * cols + 1], "char(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 1);
+ if (strcmp(typename, "bpchar") == 0)
+ {
+ if (attypmod != -1)
+ sprintf(cells[i * cols + 1], "char(%d)", attypmod - VARHDRSZ);
+ else
+ sprintf(cells[i * cols + 1], "char()");
+ }
else if (strcmp(typename, "varchar") == 0)
- sprintf(cells[i * cols + 1], "varchar(%d)", attypmod != -1 ? attypmod - VARHDRSZ : 1);
+ {
+ if (attypmod != -1)
+ sprintf(cells[i * cols + 1], "varchar(%d)", attypmod - VARHDRSZ);
+ else
+ sprintf(cells[i * cols + 1], "varchar()");
+ }
else if (strcmp(typename, "numeric") == 0)
- sprintf(cells[i * cols + 1], "numeric(%d,%d)", ((attypmod - VARHDRSZ) >> 16) & 0xffff,
+ {
+ sprintf(cells[i * cols + 1], "numeric(%d,%d)",
+ ((attypmod - VARHDRSZ) >> 16) & 0xffff,
(attypmod - VARHDRSZ) & 0xffff);
+ }
else
strcpy(cells[i * cols + 1], typename);