33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.25 2000/10/24 01:38:38 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.26 2000/10/25 20:36:52 tgl Exp $
77 */
88#include "postgres.h"
99#include "describe.h"
@@ -336,7 +336,7 @@ permissionsList(const char *name)
336336 strcat (descbuf , "SELECT relname as \"Relation\",\n"
337337 " relacl as \"Access permissions\"\n"
338338 "FROM pg_class\n"
339- "WHERE ( relkind = 'r' OR relkind = 'S') AND\n"
339+ "WHERE relkind in ( 'r', 'v', 'S') AND\n"
340340 " relname !~ '^pg_'\n" );
341341 if (name )
342342 {
@@ -570,7 +570,7 @@ describeTableDetails(const char *name, bool desc)
570570 headers [1 ] = "Type" ;
571571 cols = 2 ;
572572
573- if (tableinfo .relkind == 'r' )
573+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
574574 {
575575 cols ++ ;
576576 headers [cols - 1 ] = "Modifier" ;
@@ -634,7 +634,7 @@ describeTableDetails(const char *name, bool desc)
634634
635635 /* Extra: not null and default */
636636 /* (I'm cutting off the 'default' string at 128) */
637- if (tableinfo .relkind == 'r' )
637+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
638638 {
639639 cells [i * cols + 2 ] = xmalloc (128 + 128 );
640640 cells [i * cols + 2 ][0 ] = '\0' ;
@@ -677,10 +677,10 @@ describeTableDetails(const char *name, bool desc)
677677 switch (tableinfo .relkind )
678678 {
679679 case 'r' :
680- if ( view_def )
681- sprintf ( title , "View \"%s\"" , name ) ;
682- else
683- sprintf (title , "Table \"%s\"" , name );
680+ sprintf ( title , "Table \"%s\"" , name );
681+ break ;
682+ case 'v' :
683+ sprintf (title , "View \"%s\"" , name );
684684 break ;
685685 case 'S' :
686686 sprintf (title , "Sequence \"%s\"" , name );
@@ -692,7 +692,8 @@ describeTableDetails(const char *name, bool desc)
692692 sprintf (title , "Special relation \"%s\"" , name );
693693 break ;
694694 default :
695- sprintf (title , "?%c?" , tableinfo .relkind );
695+ sprintf (title , "?%c? \"%s\"" , tableinfo .relkind , name );
696+ break ;
696697 }
697698
698699 /* Make footers */
@@ -723,7 +724,7 @@ describeTableDetails(const char *name, bool desc)
723724 }
724725 }
725726 /* Information about the view */
726- else if (tableinfo . relkind == 'r' && view_def )
727+ else if (view_def )
727728 {
728729 footers = xmalloc (2 * sizeof (* footers ));
729730 footers [0 ] = xmalloc (20 + strlen (view_def ));
@@ -874,7 +875,7 @@ describeTableDetails(const char *name, bool desc)
874875
875876 for (i = 0 ; i < PQntuples (res ); i ++ )
876877 {
877- if (tableinfo .relkind == 'r' )
878+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
878879 free (cells [i * cols + 2 ]);
879880 }
880881 free (cells );
@@ -933,8 +934,7 @@ listTables(const char *infotype, const char *name, bool desc)
933934 if (desc )
934935 strcat (buf , ", obj_description(c.oid) as \"Description\"" );
935936 strcat (buf , "\nFROM pg_class c, pg_user u\n"
936- "WHERE c.relowner = u.usesysid AND c.relkind = 'r'\n"
937- " AND not exists (select 1 from pg_views where viewname = c.relname)\n" );
937+ "WHERE c.relowner = u.usesysid AND c.relkind = 'r'\n" );
938938 strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
939939 if (name )
940940 {
@@ -949,7 +949,6 @@ listTables(const char *infotype, const char *name, bool desc)
949949 strcat (buf , ", obj_description(c.oid) as \"Description\"" );
950950 strcat (buf , "\nFROM pg_class c\n"
951951 "WHERE c.relkind = 'r'\n"
952- " AND not exists (select 1 from pg_views where viewname = c.relname)\n"
953952 " AND not exists (select 1 from pg_user where usesysid = c.relowner)\n" );
954953 strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
955954 if (name )
@@ -970,8 +969,7 @@ listTables(const char *infotype, const char *name, bool desc)
970969 if (desc )
971970 strcat (buf , ", obj_description(c.oid) as \"Description\"" );
972971 strcat (buf , "\nFROM pg_class c, pg_user u\n"
973- "WHERE c.relowner = u.usesysid AND c.relkind = 'r'\n"
974- " AND exists (select 1 from pg_views where viewname = c.relname)\n" );
972+ "WHERE c.relowner = u.usesysid AND c.relkind = 'v'\n" );
975973 strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
976974 if (name )
977975 {
@@ -985,8 +983,7 @@ listTables(const char *infotype, const char *name, bool desc)
985983 if (desc )
986984 strcat (buf , ", obj_description(c.oid) as \"Description\"" );
987985 strcat (buf , "\nFROM pg_class c\n"
988- "WHERE c.relkind = 'r'\n"
989- " AND exists (select 1 from pg_views where viewname = c.relname)\n"
986+ "WHERE c.relkind = 'v'\n"
990987 " AND not exists (select 1 from pg_user where usesysid = c.relowner)\n" );
991988 strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
992989 if (name )
0 commit comments