Commit cc71ceab authored by Peter Eisentraut's avatar Peter Eisentraut

psql: Tab completion updates

Add/complete support for:

- ALTER DOMAIN / VALIDATE CONSTRAINT
- ALTER DOMAIN / RENAME
- ALTER DOMAIN / RENAME CONSTRAINT
- ALTER TABLE / RENAME CONSTRAINT
parent d6d5f67b
...@@ -1090,7 +1090,7 @@ psql_completion(char *text, int start, int end) ...@@ -1090,7 +1090,7 @@ psql_completion(char *text, int start, int end)
pg_strcasecmp(prev2_wd, "DOMAIN") == 0) pg_strcasecmp(prev2_wd, "DOMAIN") == 0)
{ {
static const char *const list_ALTERDOMAIN[] = static const char *const list_ALTERDOMAIN[] =
{"ADD", "DROP", "OWNER TO", "SET", NULL}; {"ADD", "DROP", "OWNER TO", "RENAME", "SET", "VALIDATE CONSTRAINT", NULL};
COMPLETE_WITH_LIST(list_ALTERDOMAIN); COMPLETE_WITH_LIST(list_ALTERDOMAIN);
} }
...@@ -1104,6 +1104,22 @@ psql_completion(char *text, int start, int end) ...@@ -1104,6 +1104,22 @@ psql_completion(char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTERDOMAIN2); COMPLETE_WITH_LIST(list_ALTERDOMAIN2);
} }
/* ALTER DOMAIN <sth> RENAME */
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "DOMAIN") == 0 &&
pg_strcasecmp(prev_wd, "RENAME") == 0)
{
static const char *const list_ALTERDOMAIN[] =
{"CONSTRAINT", "TO", NULL};
COMPLETE_WITH_LIST(list_ALTERDOMAIN);
}
/* ALTER DOMAIN <sth> RENAME CONSTRAINT <sth> */
else if (pg_strcasecmp(prev5_wd, "DOMAIN") == 0 &&
pg_strcasecmp(prev3_wd, "RENAME") == 0 &&
pg_strcasecmp(prev2_wd, "CONSTRAINT") == 0)
COMPLETE_WITH_CONST("TO");
/* ALTER DOMAIN <sth> SET */ /* ALTER DOMAIN <sth> SET */
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 && else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "DOMAIN") == 0 && pg_strcasecmp(prev3_wd, "DOMAIN") == 0 &&
...@@ -1220,12 +1236,18 @@ psql_completion(char *text, int start, int end) ...@@ -1220,12 +1236,18 @@ psql_completion(char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTERDISABLE); COMPLETE_WITH_LIST(list_ALTERDISABLE);
} }
/* If we have TABLE <sth> ALTER|RENAME, provide list of columns */ /* ALTER TABLE xxx ALTER */
else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 && else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
(pg_strcasecmp(prev_wd, "ALTER") == 0 || pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
pg_strcasecmp(prev_wd, "RENAME") == 0)) pg_strcasecmp(prev_wd, "ALTER") == 0)
COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN'"); COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN'");
/* ALTER TABLE xxx RENAME */
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
pg_strcasecmp(prev_wd, "RENAME") == 0)
COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'CONSTRAINT' UNION SELECT 'TO'");
/* /*
* If we have TABLE <sth> ALTER COLUMN|RENAME COLUMN, provide list of * If we have TABLE <sth> ALTER COLUMN|RENAME COLUMN, provide list of
* columns * columns
...@@ -1239,13 +1261,15 @@ psql_completion(char *text, int start, int end) ...@@ -1239,13 +1261,15 @@ psql_completion(char *text, int start, int end)
/* ALTER TABLE xxx RENAME yyy */ /* ALTER TABLE xxx RENAME yyy */
else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 && else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
pg_strcasecmp(prev2_wd, "RENAME") == 0 && pg_strcasecmp(prev2_wd, "RENAME") == 0 &&
pg_strcasecmp(prev_wd, "CONSTRAINT") != 0 &&
pg_strcasecmp(prev_wd, "TO") != 0) pg_strcasecmp(prev_wd, "TO") != 0)
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
/* ALTER TABLE xxx RENAME COLUMN yyy */ /* ALTER TABLE xxx RENAME COLUMN/CONSTRAINT yyy */
else if (pg_strcasecmp(prev5_wd, "TABLE") == 0 && else if (pg_strcasecmp(prev5_wd, "TABLE") == 0 &&
pg_strcasecmp(prev3_wd, "RENAME") == 0 && pg_strcasecmp(prev3_wd, "RENAME") == 0 &&
pg_strcasecmp(prev2_wd, "COLUMN") == 0 && (pg_strcasecmp(prev2_wd, "COLUMN") == 0 ||
pg_strcasecmp(prev2_wd, "CONSTRAINT") == 0) &&
pg_strcasecmp(prev_wd, "TO") != 0) pg_strcasecmp(prev_wd, "TO") != 0)
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment