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

Commit479ee09

Browse files
author
Neil Conway
committed
List disabled triggers separately in psql's "\d <table>" output.
Previously, disabled triggers were not displayed any differently thanenabled ones, which was quite misleading. Patch from Brendan Jurd.
1 parentf41803b commit479ee09

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

‎src/bin/psql/describe.c

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.149 2007/01/05 22:19:49 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.150 2007/01/20 21:17:30 neilc Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -1054,12 +1054,14 @@ describeOneTableDetails(const char *schemaname,
10541054
*result3=NULL,
10551055
*result4=NULL,
10561056
*result5=NULL,
1057-
*result6=NULL;
1057+
*result6=NULL,
1058+
*result7=NULL;
10581059
intcheck_count=0,
10591060
index_count=0,
10601061
foreignkey_count=0,
10611062
rule_count=0,
10621063
trigger_count=0,
1064+
disabled_trigger_count=0,
10631065
inherits_count=0;
10641066
intcount_footers=0;
10651067

@@ -1125,7 +1127,8 @@ describeOneTableDetails(const char *schemaname,
11251127
"SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid)\n"
11261128
"FROM pg_catalog.pg_trigger t\n"
11271129
"WHERE t.tgrelid = '%s' "
1128-
"AND (not tgisconstraint "
1130+
"AND t.tgenabled "
1131+
"AND (NOT t.tgisconstraint "
11291132
" OR NOT EXISTS"
11301133
" (SELECT 1 FROM pg_catalog.pg_depend d "
11311134
" JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
@@ -1142,6 +1145,31 @@ describeOneTableDetails(const char *schemaname,
11421145
}
11431146
else
11441147
trigger_count=PQntuples(result4);
1148+
1149+
/* acquire disabled triggers as a separate list */
1150+
printfPQExpBuffer(&buf,
1151+
"SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid)\n"
1152+
"FROM pg_catalog.pg_trigger t\n"
1153+
"WHERE t.tgrelid = '%s' "
1154+
"AND NOT t.tgenabled "
1155+
"AND (NOT t.tgisconstraint "
1156+
" OR NOT EXISTS"
1157+
" (SELECT 1 FROM pg_catalog.pg_depend d "
1158+
" JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
1159+
" WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))"
1160+
" ORDER BY 1",
1161+
oid);
1162+
result7=PSQLexec(buf.data, false);
1163+
if (!result7)
1164+
{
1165+
PQclear(result1);
1166+
PQclear(result2);
1167+
PQclear(result3);
1168+
PQclear(result4);
1169+
gotoerror_return;
1170+
}
1171+
else
1172+
disabled_trigger_count=PQntuples(result7);
11451173
}
11461174

11471175
/* count foreign-key constraints (there are none if no triggers) */
@@ -1160,6 +1188,7 @@ describeOneTableDetails(const char *schemaname,
11601188
PQclear(result2);
11611189
PQclear(result3);
11621190
PQclear(result4);
1191+
PQclear(result7);
11631192
gotoerror_return;
11641193
}
11651194
else
@@ -1177,6 +1206,7 @@ describeOneTableDetails(const char *schemaname,
11771206
PQclear(result3);
11781207
PQclear(result4);
11791208
PQclear(result5);
1209+
PQclear(result7);
11801210
gotoerror_return;
11811211
}
11821212
else
@@ -1312,6 +1342,28 @@ describeOneTableDetails(const char *schemaname,
13121342
}
13131343
}
13141344

1345+
/* print disabled triggers */
1346+
if (disabled_trigger_count>0)
1347+
{
1348+
printfPQExpBuffer(&buf,_("Disabled triggers:"));
1349+
footers[count_footers++]=pg_strdup(buf.data);
1350+
for (i=0;i<disabled_trigger_count;i++)
1351+
{
1352+
constchar*tgdef;
1353+
constchar*usingpos;
1354+
1355+
/* Everything after "TRIGGER" is echoed verbatim */
1356+
tgdef=PQgetvalue(result7,i,1);
1357+
usingpos=strstr(tgdef," TRIGGER ");
1358+
if (usingpos)
1359+
tgdef=usingpos+9;
1360+
1361+
printfPQExpBuffer(&buf," %s",tgdef);
1362+
1363+
footers[count_footers++]=pg_strdup(buf.data);
1364+
}
1365+
}
1366+
13151367
/* print inherits */
13161368
for (i=0;i<inherits_count;i++)
13171369
{
@@ -1347,6 +1399,7 @@ describeOneTableDetails(const char *schemaname,
13471399
PQclear(result4);
13481400
PQclear(result5);
13491401
PQclear(result6);
1402+
PQclear(result7);
13501403
}
13511404

13521405
printTable(title.data,headers,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp