summaryrefslogtreecommitdiff
path: root/src/bin/psql/tab-complete.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-08-20 16:30:08 -0400
committerRobert Haas <rhaas@postgresql.org>2012-08-20 16:30:08 -0400
commit68386fc15b8ba01b5a4c4ed98c4a4d4968817cc9 (patch)
tree979bd6906c4133243591f6f2ddf7ead13c13ad8e /src/bin/psql/tab-complete.c
parentb2a01b9ad1c6b074df1c4bc75ca988230dfa3cf0 (diff)
Tab complete "TABLE whatever DROP CONSTRAINT" with a constraint name.
Jeff Janes
Diffstat (limited to 'src/bin/psql/tab-complete.c')
-rw-r--r--src/bin/psql/tab-complete.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index a1bb230d6be..ef62a422eeb 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -580,6 +580,14 @@ static const SchemaQuery Query_for_list_of_views = {
" and pg_catalog.pg_table_is_visible(c2.oid)"
/* the silly-looking length condition is just to eat up the current word */
+#define Query_for_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 (%d = pg_catalog.length('%s'))"\
+" 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_list_of_tables_for_trigger \
"SELECT pg_catalog.quote_ident(relname) "\
" FROM pg_catalog.pg_class"\
@@ -1337,6 +1345,14 @@ psql_completion(char *text, int start, int end)
pg_strcasecmp(prev2_wd, "DROP") == 0 &&
pg_strcasecmp(prev_wd, "COLUMN") == 0)
COMPLETE_WITH_ATTR(prev3_wd, "");
+ /* If we have TABLE <sth> DROP CONSTRAINT, provide list of constraints */
+ else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
+ pg_strcasecmp(prev2_wd, "DROP") == 0 &&
+ pg_strcasecmp(prev_wd, "CONSTRAINT") == 0)
+ {
+ completion_info_charp = prev3_wd;
+ COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
+ }
/* ALTER TABLE ALTER [COLUMN] <foo> */
else if ((pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
pg_strcasecmp(prev2_wd, "COLUMN") == 0) ||