3
3
*
4
4
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
5
5
*
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 $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "describe.h"
@@ -1054,12 +1054,14 @@ describeOneTableDetails(const char *schemaname,
1054
1054
* result3 = NULL ,
1055
1055
* result4 = NULL ,
1056
1056
* result5 = NULL ,
1057
- * result6 = NULL ;
1057
+ * result6 = NULL ,
1058
+ * result7 = NULL ;
1058
1059
int check_count = 0 ,
1059
1060
index_count = 0 ,
1060
1061
foreignkey_count = 0 ,
1061
1062
rule_count = 0 ,
1062
1063
trigger_count = 0 ,
1064
+ disabled_trigger_count = 0 ,
1063
1065
inherits_count = 0 ;
1064
1066
int count_footers = 0 ;
1065
1067
@@ -1125,7 +1127,8 @@ describeOneTableDetails(const char *schemaname,
1125
1127
"SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid)\n"
1126
1128
"FROM pg_catalog.pg_trigger t\n"
1127
1129
"WHERE t.tgrelid = '%s' "
1128
- "AND (not tgisconstraint "
1130
+ "AND t.tgenabled "
1131
+ "AND (NOT t.tgisconstraint "
1129
1132
" OR NOT EXISTS"
1130
1133
" (SELECT 1 FROM pg_catalog.pg_depend d "
1131
1134
" JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
@@ -1142,6 +1145,31 @@ describeOneTableDetails(const char *schemaname,
1142
1145
}
1143
1146
else
1144
1147
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
+ goto error_return ;
1170
+ }
1171
+ else
1172
+ disabled_trigger_count = PQntuples (result7 );
1145
1173
}
1146
1174
1147
1175
/* count foreign-key constraints (there are none if no triggers) */
@@ -1160,6 +1188,7 @@ describeOneTableDetails(const char *schemaname,
1160
1188
PQclear (result2 );
1161
1189
PQclear (result3 );
1162
1190
PQclear (result4 );
1191
+ PQclear (result7 );
1163
1192
goto error_return ;
1164
1193
}
1165
1194
else
@@ -1177,6 +1206,7 @@ describeOneTableDetails(const char *schemaname,
1177
1206
PQclear (result3 );
1178
1207
PQclear (result4 );
1179
1208
PQclear (result5 );
1209
+ PQclear (result7 );
1180
1210
goto error_return ;
1181
1211
}
1182
1212
else
@@ -1312,6 +1342,28 @@ describeOneTableDetails(const char *schemaname,
1312
1342
}
1313
1343
}
1314
1344
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
+ const char * tgdef ;
1353
+ const char * 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
+
1315
1367
/* print inherits */
1316
1368
for (i = 0 ; i < inherits_count ; i ++ )
1317
1369
{
@@ -1347,6 +1399,7 @@ describeOneTableDetails(const char *schemaname,
1347
1399
PQclear (result4 );
1348
1400
PQclear (result5 );
1349
1401
PQclear (result6 );
1402
+ PQclear (result7 );
1350
1403
}
1351
1404
1352
1405
printTable (title .data , headers ,
0 commit comments