3
3
*
4
4
* Copyright 2000 by PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres.h"
9
9
#include "describe.h"
@@ -336,7 +336,7 @@ permissionsList(const char *name)
336
336
strcat (descbuf , "SELECT relname as \"Relation\",\n"
337
337
" relacl as \"Access permissions\"\n"
338
338
"FROM pg_class\n"
339
- "WHERE ( relkind = 'r' OR relkind = 'S') AND\n"
339
+ "WHERE relkind in ( 'r', 'v', 'S') AND\n"
340
340
" relname !~ '^pg_'\n" );
341
341
if (name )
342
342
{
@@ -570,7 +570,7 @@ describeTableDetails(const char *name, bool desc)
570
570
headers [1 ] = "Type" ;
571
571
cols = 2 ;
572
572
573
- if (tableinfo .relkind == 'r' )
573
+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
574
574
{
575
575
cols ++ ;
576
576
headers [cols - 1 ] = "Modifier" ;
@@ -634,7 +634,7 @@ describeTableDetails(const char *name, bool desc)
634
634
635
635
/* Extra: not null and default */
636
636
/* (I'm cutting off the 'default' string at 128) */
637
- if (tableinfo .relkind == 'r' )
637
+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
638
638
{
639
639
cells [i * cols + 2 ] = xmalloc (128 + 128 );
640
640
cells [i * cols + 2 ][0 ] = '\0' ;
@@ -677,10 +677,10 @@ describeTableDetails(const char *name, bool desc)
677
677
switch (tableinfo .relkind )
678
678
{
679
679
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 );
684
684
break ;
685
685
case 'S' :
686
686
sprintf (title , "Sequence \"%s\"" , name );
@@ -692,7 +692,8 @@ describeTableDetails(const char *name, bool desc)
692
692
sprintf (title , "Special relation \"%s\"" , name );
693
693
break ;
694
694
default :
695
- sprintf (title , "?%c?" , tableinfo .relkind );
695
+ sprintf (title , "?%c? \"%s\"" , tableinfo .relkind , name );
696
+ break ;
696
697
}
697
698
698
699
/* Make footers */
@@ -723,7 +724,7 @@ describeTableDetails(const char *name, bool desc)
723
724
}
724
725
}
725
726
/* Information about the view */
726
- else if (tableinfo . relkind == 'r' && view_def )
727
+ else if (view_def )
727
728
{
728
729
footers = xmalloc (2 * sizeof (* footers ));
729
730
footers [0 ] = xmalloc (20 + strlen (view_def ));
@@ -874,7 +875,7 @@ describeTableDetails(const char *name, bool desc)
874
875
875
876
for (i = 0 ; i < PQntuples (res ); i ++ )
876
877
{
877
- if (tableinfo .relkind == 'r' )
878
+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
878
879
free (cells [i * cols + 2 ]);
879
880
}
880
881
free (cells );
@@ -933,8 +934,7 @@ listTables(const char *infotype, const char *name, bool desc)
933
934
if (desc )
934
935
strcat (buf , ", obj_description(c.oid) as \"Description\"" );
935
936
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" );
938
938
strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
939
939
if (name )
940
940
{
@@ -949,7 +949,6 @@ listTables(const char *infotype, const char *name, bool desc)
949
949
strcat (buf , ", obj_description(c.oid) as \"Description\"" );
950
950
strcat (buf , "\nFROM pg_class c\n"
951
951
"WHERE c.relkind = 'r'\n"
952
- " AND not exists (select 1 from pg_views where viewname = c.relname)\n"
953
952
" AND not exists (select 1 from pg_user where usesysid = c.relowner)\n" );
954
953
strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
955
954
if (name )
@@ -970,8 +969,7 @@ listTables(const char *infotype, const char *name, bool desc)
970
969
if (desc )
971
970
strcat (buf , ", obj_description(c.oid) as \"Description\"" );
972
971
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" );
975
973
strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
976
974
if (name )
977
975
{
@@ -985,8 +983,7 @@ listTables(const char *infotype, const char *name, bool desc)
985
983
if (desc )
986
984
strcat (buf , ", obj_description(c.oid) as \"Description\"" );
987
985
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"
990
987
" AND not exists (select 1 from pg_user where usesysid = c.relowner)\n" );
991
988
strcat (buf , showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n" );
992
989
if (name )
0 commit comments