@@ -579,6 +579,14 @@ static const SchemaQuery Query_for_list_of_views = {
579579" and pg_catalog.quote_ident(c1.relname)='%s'"\
580580" and pg_catalog.pg_table_is_visible(c2.oid)"
581581
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+
582590/* the silly-looking length condition is just to eat up the current word */
583591#define Query_for_list_of_tables_for_trigger \
584592"SELECT pg_catalog.quote_ident(relname) "\
@@ -1337,6 +1345,14 @@ psql_completion(char *text, int start, int end)
13371345 pg_strcasecmp (prev2_wd , "DROP" ) == 0 &&
13381346 pg_strcasecmp (prev_wd , "COLUMN" ) == 0 )
13391347 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+ }
13401356 /* ALTER TABLE ALTER [COLUMN] <foo> */
13411357 else if ((pg_strcasecmp (prev3_wd , "ALTER" ) == 0 &&
13421358 pg_strcasecmp (prev2_wd , "COLUMN" ) == 0 ) ||
0 commit comments