Skip to content

Commit 68386fc

Browse files
committed
Tab complete "TABLE whatever DROP CONSTRAINT" with a constraint name.
Jeff Janes
1 parent b2a01b9 commit 68386fc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/bin/psql/tab-complete.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy