Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcbf4c96

Browse files
committed
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. Thelatter effectively have an unspecified length, so I made them displayas char() and varchar() rather than falsely equating them to char(1)and varchar(1).
1 parent6f11af0 commitcbf4c96

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

‎src/bin/psql/describe.c

Lines changed: 19 additions & 8 deletions
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.17 2000/02/16 13:15:26 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.18 2000/02/26 18:31:25 tgl Exp $
77
*/
88
#include"postgres.h"
99
#include"describe.h"
@@ -631,9 +631,7 @@ describeTableDetails(const char *name, bool desc)
631631
attype++;
632632
}
633633
/* (convert some internal type names to SQL'ish) */
634-
if (strcmp(attype,"bpchar")==0)
635-
typename="char";
636-
elseif (strcmp(attype,"int2")==0)
634+
if (strcmp(attype,"int2")==0)
637635
typename="smallint";
638636
elseif (strcmp(attype,"int4")==0)
639637
typename="integer";
@@ -646,13 +644,26 @@ describeTableDetails(const char *name, bool desc)
646644
/* more might need to be added when date/time types are sorted out */
647645

648646
cells[i*cols+1]=xmalloc(NAMEDATALEN+16);
649-
if (strcmp(typename,"char")==0)
650-
sprintf(cells[i*cols+1],"char(%d)",attypmod!=-1 ?attypmod-VARHDRSZ :1);
647+
if (strcmp(typename,"bpchar")==0)
648+
{
649+
if (attypmod!=-1)
650+
sprintf(cells[i*cols+1],"char(%d)",attypmod-VARHDRSZ);
651+
else
652+
sprintf(cells[i*cols+1],"char()");
653+
}
651654
elseif (strcmp(typename,"varchar")==0)
652-
sprintf(cells[i*cols+1],"varchar(%d)",attypmod!=-1 ?attypmod-VARHDRSZ :1);
655+
{
656+
if (attypmod!=-1)
657+
sprintf(cells[i*cols+1],"varchar(%d)",attypmod-VARHDRSZ);
658+
else
659+
sprintf(cells[i*cols+1],"varchar()");
660+
}
653661
elseif (strcmp(typename,"numeric")==0)
654-
sprintf(cells[i*cols+1],"numeric(%d,%d)", ((attypmod-VARHDRSZ) >>16)&0xffff,
662+
{
663+
sprintf(cells[i*cols+1],"numeric(%d,%d)",
664+
((attypmod-VARHDRSZ) >>16)&0xffff,
655665
(attypmod-VARHDRSZ)&0xffff);
666+
}
656667
else
657668
strcpy(cells[i*cols+1],typename);
658669

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp