Commit 4bad548d authored by Bruce Momjian's avatar Bruce Momjian

psql: add separate \d display for disabled system triggers

Previously if you disabled all triggers, only user triggers would
show as disabled

Per report from Andres Freund
parent d613861b
...@@ -2090,15 +2090,19 @@ describeOneTableDetails(const char *schemaname, ...@@ -2090,15 +2090,19 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT t.tgname, " "SELECT t.tgname, "
"pg_catalog.pg_get_triggerdef(t.oid%s), " "pg_catalog.pg_get_triggerdef(t.oid%s), "
"t.tgenabled\n" "t.tgenabled, %s\n"
"FROM pg_catalog.pg_trigger t\n" "FROM pg_catalog.pg_trigger t\n"
"WHERE t.tgrelid = '%s' AND ", "WHERE t.tgrelid = '%s' AND ",
(pset.sversion >= 90000 ? ", true" : ""), (pset.sversion >= 90000 ? ", true" : ""),
oid); (pset.sversion >= 90000 ? "t.tgisinternal" :
pset.sversion >= 80300 ?
"t.tgconstraint <> 0 AS tgisinternal" :
"false AS tgisinternal"), oid);
if (pset.sversion >= 90000) if (pset.sversion >= 90000)
appendPQExpBufferStr(&buf, "NOT t.tgisinternal"); /* display/warn about disabled internal triggers */
appendPQExpBuffer(&buf, "(NOT t.tgisinternal OR (t.tgisinternal AND t.tgenabled = 'D'))");
else if (pset.sversion >= 80300) else if (pset.sversion >= 80300)
appendPQExpBufferStr(&buf, "t.tgconstraint = 0"); appendPQExpBufferStr(&buf, "(t.tgconstraint = 0 OR (t.tgconstraint <> 0 AND t.tgenabled = 'D'))");
else else
appendPQExpBufferStr(&buf, appendPQExpBufferStr(&buf,
"(NOT tgisconstraint " "(NOT tgisconstraint "
...@@ -2124,7 +2128,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -2124,7 +2128,7 @@ describeOneTableDetails(const char *schemaname,
* disabled triggers and the two special ALWAYS and REPLICA * disabled triggers and the two special ALWAYS and REPLICA
* configurations. * configurations.
*/ */
for (category = 0; category < 4; category++) for (category = 0; category <= 4; category++)
{ {
have_heading = false; have_heading = false;
for (i = 0; i < tuples; i++) for (i = 0; i < tuples; i++)
...@@ -2133,11 +2137,13 @@ describeOneTableDetails(const char *schemaname, ...@@ -2133,11 +2137,13 @@ describeOneTableDetails(const char *schemaname,
const char *tgdef; const char *tgdef;
const char *usingpos; const char *usingpos;
const char *tgenabled; const char *tgenabled;
const char *tgisinternal;
/* /*
* Check if this trigger falls into the current category * Check if this trigger falls into the current category
*/ */
tgenabled = PQgetvalue(result, i, 2); tgenabled = PQgetvalue(result, i, 2);
tgisinternal = PQgetvalue(result, i, 3);
list_trigger = false; list_trigger = false;
switch (category) switch (category)
{ {
...@@ -2146,14 +2152,20 @@ describeOneTableDetails(const char *schemaname, ...@@ -2146,14 +2152,20 @@ describeOneTableDetails(const char *schemaname,
list_trigger = true; list_trigger = true;
break; break;
case 1: case 1:
if (*tgenabled == 'D' || *tgenabled == 'f') if ((*tgenabled == 'D' || *tgenabled == 'f') &&
*tgisinternal == 'f')
list_trigger = true; list_trigger = true;
break; break;
case 2: case 2:
if (*tgenabled == 'A') if ((*tgenabled == 'D' || *tgenabled == 'f') &&
*tgisinternal == 't')
list_trigger = true; list_trigger = true;
break; break;
case 3: case 3:
if (*tgenabled == 'A')
list_trigger = true;
break;
case 4:
if (*tgenabled == 'R') if (*tgenabled == 'R')
list_trigger = true; list_trigger = true;
break; break;
...@@ -2170,12 +2182,18 @@ describeOneTableDetails(const char *schemaname, ...@@ -2170,12 +2182,18 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, _("Triggers:")); printfPQExpBuffer(&buf, _("Triggers:"));
break; break;
case 1: case 1:
if (pset.sversion >= 80300)
printfPQExpBuffer(&buf, _("Disabled user triggers:"));
else
printfPQExpBuffer(&buf, _("Disabled triggers:")); printfPQExpBuffer(&buf, _("Disabled triggers:"));
break; break;
case 2: case 2:
printfPQExpBuffer(&buf, _("Triggers firing always:")); printfPQExpBuffer(&buf, _("Disabled internal triggers:"));
break; break;
case 3: case 3:
printfPQExpBuffer(&buf, _("Triggers firing always:"));
break;
case 4:
printfPQExpBuffer(&buf, _("Triggers firing on replica only:")); printfPQExpBuffer(&buf, _("Triggers firing on replica only:"));
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment