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

Commitaab0b8f

Browse files
committed
I was tinkering with creating rules on views (so, for instance, one could
insert on a view), and noticed that psql wouldn't show the list of rulesset up on a view, like it does for tables.The fix was extremely simple, so I figured I'd share it. Not sure whatthe standard is for communicating these things, so I've attached the difffile for /src/bin/psql/describe.c.Paul (?)
1 parent9f20765 commitaab0b8f

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

‎src/bin/psql/describe.c

Lines changed: 44 additions & 5 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.47 2002/03/20 19:44:45 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.48 2002/04/05 11:52:38 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -692,12 +692,51 @@ describeTableDetails(const char *name, bool desc)
692692
}
693693
elseif (view_def)
694694
{
695+
PGresult*result=NULL;
696+
intrule_count=0;
697+
intcount_footers=0;
698+
699+
/* count rules */
700+
if (!error&&tableinfo.hasrules)
701+
{
702+
sprintf(buf,
703+
"SELECT r.rulename\n"
704+
"FROM pg_rewrite r, pg_class c\n"
705+
"WHERE c.relname='%s' AND c.oid = r.ev_class\n"
706+
"AND r.rulename NOT LIKE '_RET%%'",
707+
name);
708+
result=PSQLexec(buf);
709+
if (!result)
710+
error= true;
711+
else
712+
rule_count=PQntuples(result);
713+
}
714+
695715
/* Footer information about a view */
696-
footers=xmalloc(2*sizeof(*footers));
697-
footers[0]=xmalloc(64+strlen(view_def));
698-
snprintf(footers[0],64+strlen(view_def),
716+
footers=xmalloc((rule_count+2)*sizeof(*footers));
717+
footers[count_footers]=xmalloc(64+strlen(view_def));
718+
snprintf(footers[count_footers],64+strlen(view_def),
699719
_("View definition: %s"),view_def);
700-
footers[1]=NULL;
720+
count_footers++;
721+
722+
/* print rules */
723+
for (i=0;i<rule_count;i++)
724+
{
725+
char*s=_("Rules");
726+
727+
if (i==0)
728+
snprintf(buf,sizeof(buf),"%s: %s",s,PQgetvalue(result,i,0));
729+
else
730+
snprintf(buf,sizeof(buf),"%*s %s", (int)strlen(s),"",PQgetvalue(result,i,0));
731+
if (i<rule_count-1)
732+
strcat(buf,",");
733+
734+
footers[count_footers++]=xstrdup(buf);
735+
}
736+
PQclear(result);
737+
738+
footers[count_footers]=NULL;
739+
701740
}
702741
elseif (tableinfo.relkind=='r')
703742
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp