@@ -579,6 +579,14 @@ static const SchemaQuery Query_for_list_of_views = {
579
579
" and pg_catalog.quote_ident(c1.relname)='%s'"\
580
580
" and pg_catalog.pg_table_is_visible(c2.oid)"
581
581
582
+ /* the silly-looking length condition is just to eat up the current word */
583
+ #define Query_for_constraint_of_table \
584
+ "SELECT pg_catalog.quote_ident(conname) "\
585
+ " FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\
586
+ " WHERE c1.oid=conrelid and (%d = pg_catalog.length('%s'))"\
587
+ " and pg_catalog.quote_ident(c1.relname)='%s'"\
588
+ " and pg_catalog.pg_table_is_visible(c1.oid)"
589
+
582
590
/* the silly-looking length condition is just to eat up the current word */
583
591
#define Query_for_list_of_tables_for_trigger \
584
592
"SELECT pg_catalog.quote_ident(relname) "\
@@ -1337,6 +1345,14 @@ psql_completion(char *text, int start, int end)
1337
1345
pg_strcasecmp (prev2_wd , "DROP" ) == 0 &&
1338
1346
pg_strcasecmp (prev_wd , "COLUMN" ) == 0 )
1339
1347
COMPLETE_WITH_ATTR (prev3_wd , "" );
1348
+ /* If we have TABLE <sth> DROP CONSTRAINT, provide list of constraints */
1349
+ else if (pg_strcasecmp (prev4_wd , "TABLE" ) == 0 &&
1350
+ pg_strcasecmp (prev2_wd , "DROP" ) == 0 &&
1351
+ pg_strcasecmp (prev_wd , "CONSTRAINT" ) == 0 )
1352
+ {
1353
+ completion_info_charp = prev3_wd ;
1354
+ COMPLETE_WITH_QUERY (Query_for_constraint_of_table );
1355
+ }
1340
1356
/* ALTER TABLE ALTER [COLUMN] <foo> */
1341
1357
else if ((pg_strcasecmp (prev3_wd , "ALTER" ) == 0 &&
1342
1358
pg_strcasecmp (prev2_wd , "COLUMN" ) == 0 ) ||
0 commit comments