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)
336336strcat (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 relkindin ( 'r', 'v', 'S') AND\n"
340340" relname !~ '^pg_'\n" );
341341if (name )
342342{
@@ -570,7 +570,7 @@ describeTableDetails(const char *name, bool desc)
570570headers [1 ]= "Type" ;
571571cols = 2 ;
572572
573- if (tableinfo .relkind == 'r' )
573+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
574574{
575575cols ++ ;
576576headers [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{
639639cells [i * cols + 2 ]= xmalloc (128 + 128 );
640640cells [i * cols + 2 ][0 ]= '\0' ;
@@ -677,10 +677,10 @@ describeTableDetails(const char *name, bool desc)
677677switch (tableinfo .relkind )
678678{
679679case '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 );
684684break ;
685685case 'S' :
686686sprintf (title ,"Sequence \"%s\"" ,name );
@@ -692,7 +692,8 @@ describeTableDetails(const char *name, bool desc)
692692sprintf (title ,"Special relation \"%s\"" ,name );
693693break ;
694694default :
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{
728729footers = xmalloc (2 * sizeof (* footers ));
729730footers [0 ]= xmalloc (20 + strlen (view_def ));
@@ -874,7 +875,7 @@ describeTableDetails(const char *name, bool desc)
874875
875876for (i = 0 ;i < PQntuples (res );i ++ )
876877{
877- if (tableinfo .relkind == 'r' )
878+ if (tableinfo .relkind == 'r' || tableinfo . relkind == 'v' )
878879free (cells [i * cols + 2 ]);
879880}
880881free (cells );
@@ -933,8 +934,7 @@ listTables(const char *infotype, const char *name, bool desc)
933934if (desc )
934935strcat (buf ,", obj_description(c.oid) as \"Description\"" );
935936strcat (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" );
938938strcat (buf ,showSystem ?" AND c.relname ~ '^pg_'\n" :" AND c.relname !~ '^pg_'\n" );
939939if (name )
940940{
@@ -949,7 +949,6 @@ listTables(const char *infotype, const char *name, bool desc)
949949strcat (buf ,", obj_description(c.oid) as \"Description\"" );
950950strcat (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" );
954953strcat (buf ,showSystem ?" AND c.relname ~ '^pg_'\n" :" AND c.relname !~ '^pg_'\n" );
955954if (name )
@@ -970,8 +969,7 @@ listTables(const char *infotype, const char *name, bool desc)
970969if (desc )
971970strcat (buf ,", obj_description(c.oid) as \"Description\"" );
972971strcat (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" );
975973strcat (buf ,showSystem ?" AND c.relname ~ '^pg_'\n" :" AND c.relname !~ '^pg_'\n" );
976974if (name )
977975{
@@ -985,8 +983,7 @@ listTables(const char *infotype, const char *name, bool desc)
985983if (desc )
986984strcat (buf ,", obj_description(c.oid) as \"Description\"" );
987985strcat (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" );
991988strcat (buf ,showSystem ?" AND c.relname ~ '^pg_'\n" :" AND c.relname !~ '^pg_'\n" );
992989if (name )