diff --git src/bin/psql/tab-complete.c src/bin/psql/tab-complete.c index 7c4933333b..b1bca24714 100644 --- src/bin/psql/tab-complete.c +++ src/bin/psql/tab-complete.c @@ -785,6 +785,15 @@ static const SchemaQuery Query_for_list_of_collations = { " and pg_catalog.quote_ident(c1.relname)='%s'"\ " and pg_catalog.pg_table_is_visible(c1.oid)" +/* the silly-looking length condition is just to eat up the current word */ +#define Query_for_nonvalid_constraint_of_table \ +"SELECT pg_catalog.quote_ident(conname) "\ +" FROM pg_catalog.pg_class c1, pg_catalog.pg_constraint con "\ +" WHERE c1.oid=conrelid and not convalidated"\ +" and (%d = pg_catalog.length('%s'))"\ +" and pg_catalog.quote_ident(c1.relname)='%s'"\ +" and pg_catalog.pg_table_is_visible(c1.oid)" + #define Query_for_all_table_constraints \ "SELECT pg_catalog.quote_ident(conname) "\ " FROM pg_catalog.pg_constraint c "\ @@ -2118,11 +2127,16 @@ psql_completion(const char *text, int start, int end) * If we have ALTER TABLE ALTER|DROP|RENAME|VALIDATE CONSTRAINT, * provide list of constraints */ - else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT")) + else if (Matches("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME", "CONSTRAINT")) { completion_info_charp = prev3_wd; COMPLETE_WITH_QUERY(Query_for_constraint_of_table); } + else if (Matches("ALTER", "TABLE", MatchAny, "VALIDATE", "CONSTRAINT")) + { + completion_info_charp = prev3_wd; + COMPLETE_WITH_QUERY(Query_for_nonvalid_constraint_of_table); + } /* ALTER TABLE ALTER [COLUMN] */ else if (Matches("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) || Matches("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))