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

Commit4ad9fe4

Browse files
committed
Teach psql about new relkind for views.
1 parent0a63b6d commit4ad9fe4

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

‎src/bin/psql/describe.c

Lines changed: 15 additions & 18 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.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 relkindin ('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-
elseif (tableinfo.relkind=='r'&&view_def)
727+
elseif (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)

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 2 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/tab-complete.c,v 1.21 2000/10/03 19:50:20 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.22 2000/10/25 20:36:52 tgl Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -519,7 +519,7 @@ psql_completion(char *text, int start, int end)
519519
*/
520520
elseif ((strcasecmp(prev3_wd,"GRANT")==0||strcasecmp(prev3_wd,"REVOKE")==0)&&
521521
strcasecmp(prev_wd,"ON")==0)
522-
COMPLETE_WITH_QUERY("SELECT relname FROM pg_class WHERE relkind in ('r','i','s') and substr(relname,1,%d)='%s'");
522+
COMPLETE_WITH_QUERY("SELECT relname FROM pg_class WHERE relkind in ('r','i','S','v') and substr(relname,1,%d)='%s'");
523523
/* Complete "GRANT * ON * " with "TO" */
524524
elseif (strcasecmp(prev4_wd,"GRANT")==0&&strcasecmp(prev2_wd,"ON")==0)
525525
COMPLETE_WITH_CONST("TO");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp