Commit 9b181b03 authored by Tom Lane's avatar Tom Lane

In psql's tab completion, change most TailMatches patterns to Matches.

In the refactoring in commit d37b816d,
we mostly kept to the original design whereby only the last few words
on the line were matched to identify a completable pattern.  However,
after commit d854118c, there's really
no reason to do it like that: where it's sensible, we can use patterns
that expect to match the entire input line.  And mostly, it's sensible.
Matching the entire line greatly reduces the odds of a false match that
leads to offering irrelevant completions.  Moreover (though I've not
tried to measure this), it should make tab completion faster since
many of the patterns will be discarded after a single integer comparison
that finds that the wrong number of words appear on the line.

There are certain identifiable places where we still need to use
TailMatches because the statement in question is allowed to appear
embedded in a larger statement.  These are just a small minority of
the existing patterns, though, so the benefit of switching where
possible is large.

It's possible that this patch has removed some within-line matching
behaviors that are in fact desirable, but we can put those back when
we get complaints.  Most of the removed behaviors are certainly silly.

Michael Paquier, with some further adjustments by me
parent 7debf360
...@@ -1137,6 +1137,21 @@ psql_completion(const char *text, int start, int end) ...@@ -1137,6 +1137,21 @@ psql_completion(const char *text, int start, int end)
#define Matches4(p1, p2, p3, p4) \ #define Matches4(p1, p2, p3, p4) \
(previous_words_count == 4 && \ (previous_words_count == 4 && \
TailMatches4(p1, p2, p3, p4)) TailMatches4(p1, p2, p3, p4))
#define Matches5(p1, p2, p3, p4, p5) \
(previous_words_count == 5 && \
TailMatches5(p1, p2, p3, p4, p5))
#define Matches6(p1, p2, p3, p4, p5, p6) \
(previous_words_count == 6 && \
TailMatches6(p1, p2, p3, p4, p5, p6))
#define Matches7(p1, p2, p3, p4, p5, p6, p7) \
(previous_words_count == 7 && \
TailMatches7(p1, p2, p3, p4, p5, p6, p7))
#define Matches8(p1, p2, p3, p4, p5, p6, p7, p8) \
(previous_words_count == 8 && \
TailMatches8(p1, p2, p3, p4, p5, p6, p7, p8))
#define Matches9(p1, p2, p3, p4, p5, p6, p7, p8, p9) \
(previous_words_count == 9 && \
TailMatches9(p1, p2, p3, p4, p5, p6, p7, p8, p9))
/* /*
* Macros for matching N words at the start of the line, regardless of * Macros for matching N words at the start of the line, regardless of
...@@ -1266,10 +1281,10 @@ psql_completion(const char *text, int start, int end) ...@@ -1266,10 +1281,10 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches7("ALL", "IN", "TABLESPACE", MatchAny, "OWNED", "BY", MatchAny)) else if (TailMatches7("ALL", "IN", "TABLESPACE", MatchAny, "OWNED", "BY", MatchAny))
COMPLETE_WITH_CONST("SET TABLESPACE"); COMPLETE_WITH_CONST("SET TABLESPACE");
/* ALTER AGGREGATE,FUNCTION <name> */ /* ALTER AGGREGATE,FUNCTION <name> */
else if (TailMatches3("ALTER", "AGGREGATE|FUNCTION", MatchAny)) else if (Matches3("ALTER", "AGGREGATE|FUNCTION", MatchAny))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER AGGREGATE,FUNCTION <name> (...) */ /* ALTER AGGREGATE,FUNCTION <name> (...) */
else if (TailMatches4("ALTER", "AGGREGATE|FUNCTION", MatchAny, MatchAny)) else if (Matches4("ALTER", "AGGREGATE|FUNCTION", MatchAny, MatchAny))
{ {
if (ends_with(prev_wd, ')')) if (ends_with(prev_wd, ')'))
COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA"); COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA");
...@@ -1278,49 +1293,49 @@ psql_completion(const char *text, int start, int end) ...@@ -1278,49 +1293,49 @@ psql_completion(const char *text, int start, int end)
} }
/* ALTER SCHEMA <name> */ /* ALTER SCHEMA <name> */
else if (TailMatches3("ALTER", "SCHEMA", MatchAny)) else if (Matches3("ALTER", "SCHEMA", MatchAny))
COMPLETE_WITH_LIST2("OWNER TO", "RENAME TO"); COMPLETE_WITH_LIST2("OWNER TO", "RENAME TO");
/* ALTER COLLATION <name> */ /* ALTER COLLATION <name> */
else if (TailMatches3("ALTER", "COLLATION", MatchAny)) else if (Matches3("ALTER", "COLLATION", MatchAny))
COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA"); COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA");
/* ALTER CONVERSION <name> */ /* ALTER CONVERSION <name> */
else if (TailMatches3("ALTER", "CONVERSION", MatchAny)) else if (Matches3("ALTER", "CONVERSION", MatchAny))
COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA"); COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA");
/* ALTER DATABASE <name> */ /* ALTER DATABASE <name> */
else if (TailMatches3("ALTER", "DATABASE", MatchAny)) else if (Matches3("ALTER", "DATABASE", MatchAny))
COMPLETE_WITH_LIST7("RESET", "SET", "OWNER TO", "RENAME TO", COMPLETE_WITH_LIST7("RESET", "SET", "OWNER TO", "RENAME TO",
"IS_TEMPLATE", "ALLOW_CONNECTIONS", "IS_TEMPLATE", "ALLOW_CONNECTIONS",
"CONNECTION LIMIT"); "CONNECTION LIMIT");
/* ALTER EVENT TRIGGER */ /* ALTER EVENT TRIGGER */
else if (TailMatches3("ALTER", "EVENT", "TRIGGER")) else if (Matches3("ALTER", "EVENT", "TRIGGER"))
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
/* ALTER EVENT TRIGGER <name> */ /* ALTER EVENT TRIGGER <name> */
else if (TailMatches4("ALTER", "EVENT", "TRIGGER", MatchAny)) else if (Matches4("ALTER", "EVENT", "TRIGGER", MatchAny))
COMPLETE_WITH_LIST4("DISABLE", "ENABLE", "OWNER TO", "RENAME TO"); COMPLETE_WITH_LIST4("DISABLE", "ENABLE", "OWNER TO", "RENAME TO");
/* ALTER EVENT TRIGGER <name> ENABLE */ /* ALTER EVENT TRIGGER <name> ENABLE */
else if (TailMatches5("ALTER", "EVENT", "TRIGGER", MatchAny, "ENABLE")) else if (Matches5("ALTER", "EVENT", "TRIGGER", MatchAny, "ENABLE"))
COMPLETE_WITH_LIST2("REPLICA", "ALWAYS"); COMPLETE_WITH_LIST2("REPLICA", "ALWAYS");
/* ALTER EXTENSION <name> */ /* ALTER EXTENSION <name> */
else if (TailMatches3("ALTER", "EXTENSION", MatchAny)) else if (Matches3("ALTER", "EXTENSION", MatchAny))
COMPLETE_WITH_LIST4("ADD", "DROP", "UPDATE", "SET SCHEMA"); COMPLETE_WITH_LIST4("ADD", "DROP", "UPDATE", "SET SCHEMA");
/* ALTER FOREIGN */ /* ALTER FOREIGN */
else if (TailMatches2("ALTER", "FOREIGN")) else if (Matches2("ALTER", "FOREIGN"))
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE"); COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
/* ALTER FOREIGN DATA WRAPPER <name> */ /* ALTER FOREIGN DATA WRAPPER <name> */
else if (TailMatches5("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny)) else if (Matches5("ALTER", "FOREIGN", "DATA", "WRAPPER", MatchAny))
COMPLETE_WITH_LIST4("HANDLER", "VALIDATOR", "OPTIONS", "OWNER TO"); COMPLETE_WITH_LIST4("HANDLER", "VALIDATOR", "OPTIONS", "OWNER TO");
/* ALTER FOREIGN TABLE <name> */ /* ALTER FOREIGN TABLE <name> */
else if (TailMatches4("ALTER", "FOREIGN", "TABLE", MatchAny)) else if (Matches4("ALTER", "FOREIGN", "TABLE", MatchAny))
{ {
static const char *const list_ALTER_FOREIGN_TABLE[] = static const char *const list_ALTER_FOREIGN_TABLE[] =
{"ADD", "ALTER", "DISABLE TRIGGER", "DROP", "ENABLE", "INHERIT", {"ADD", "ALTER", "DISABLE TRIGGER", "DROP", "ENABLE", "INHERIT",
...@@ -1331,41 +1346,41 @@ psql_completion(const char *text, int start, int end) ...@@ -1331,41 +1346,41 @@ psql_completion(const char *text, int start, int end)
} }
/* ALTER INDEX */ /* ALTER INDEX */
else if (TailMatches2("ALTER", "INDEX")) else if (Matches2("ALTER", "INDEX"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
"UNION SELECT 'ALL IN TABLESPACE'"); "UNION SELECT 'ALL IN TABLESPACE'");
/* ALTER INDEX <name> */ /* ALTER INDEX <name> */
else if (TailMatches3("ALTER", "INDEX", MatchAny)) else if (Matches3("ALTER", "INDEX", MatchAny))
COMPLETE_WITH_LIST4("OWNER TO", "RENAME TO", "SET", "RESET"); COMPLETE_WITH_LIST4("OWNER TO", "RENAME TO", "SET", "RESET");
/* ALTER INDEX <name> SET */ /* ALTER INDEX <name> SET */
else if (TailMatches4("ALTER", "INDEX", MatchAny, "SET")) else if (Matches4("ALTER", "INDEX", MatchAny, "SET"))
COMPLETE_WITH_LIST2("(", "TABLESPACE"); COMPLETE_WITH_LIST2("(", "TABLESPACE");
/* ALTER INDEX <name> RESET */ /* ALTER INDEX <name> RESET */
else if (TailMatches4("ALTER", "INDEX", MatchAny, "RESET")) else if (Matches4("ALTER", "INDEX", MatchAny, "RESET"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER INDEX <foo> SET|RESET ( */ /* ALTER INDEX <foo> SET|RESET ( */
else if (TailMatches5("ALTER", "INDEX", MatchAny, "RESET", "(")) else if (Matches5("ALTER", "INDEX", MatchAny, "RESET", "("))
COMPLETE_WITH_LIST3("fillfactor", "fastupdate", COMPLETE_WITH_LIST3("fillfactor", "fastupdate",
"gin_pending_list_limit"); "gin_pending_list_limit");
else if (TailMatches5("ALTER", "INDEX", MatchAny, "SET", "(")) else if (Matches5("ALTER", "INDEX", MatchAny, "SET", "("))
COMPLETE_WITH_LIST3("fillfactor =", "fastupdate =", COMPLETE_WITH_LIST3("fillfactor =", "fastupdate =",
"gin_pending_list_limit ="); "gin_pending_list_limit =");
/* ALTER LANGUAGE <name> */ /* ALTER LANGUAGE <name> */
else if (TailMatches3("ALTER", "LANGUAGE", MatchAny)) else if (Matches3("ALTER", "LANGUAGE", MatchAny))
COMPLETE_WITH_LIST2("OWNER_TO", "RENAME TO"); COMPLETE_WITH_LIST2("OWNER_TO", "RENAME TO");
/* ALTER LARGE OBJECT <oid> */ /* ALTER LARGE OBJECT <oid> */
else if (TailMatches4("ALTER", "LARGE", "OBJECT", MatchAny)) else if (Matches4("ALTER", "LARGE", "OBJECT", MatchAny))
COMPLETE_WITH_CONST("OWNER TO"); COMPLETE_WITH_CONST("OWNER TO");
/* ALTER MATERIALIZED VIEW */ /* ALTER MATERIALIZED VIEW */
else if (TailMatches3("ALTER", "MATERIALIZED", "VIEW")) else if (Matches3("ALTER", "MATERIALIZED", "VIEW"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews,
"UNION SELECT 'ALL IN TABLESPACE'"); "UNION SELECT 'ALL IN TABLESPACE'");
/* ALTER USER,ROLE <name> */ /* ALTER USER,ROLE <name> */
else if (TailMatches3("ALTER", "USER|ROLE", MatchAny) && else if (Matches3("ALTER", "USER|ROLE", MatchAny) &&
!TailMatches2("USER", "MAPPING")) !TailMatches2("USER", "MAPPING"))
{ {
static const char *const list_ALTERUSER[] = static const char *const list_ALTERUSER[] =
...@@ -1380,7 +1395,7 @@ psql_completion(const char *text, int start, int end) ...@@ -1380,7 +1395,7 @@ psql_completion(const char *text, int start, int end)
} }
/* ALTER USER,ROLE <name> WITH */ /* ALTER USER,ROLE <name> WITH */
else if (TailMatches4("ALTER", "USER|ROLE", MatchAny, "WITH")) else if (Matches4("ALTER", "USER|ROLE", MatchAny, "WITH"))
{ {
/* Similar to the above, but don't complete "WITH" again. */ /* Similar to the above, but don't complete "WITH" again. */
static const char *const list_ALTERUSER_WITH[] = static const char *const list_ALTERUSER_WITH[] =
...@@ -1395,43 +1410,43 @@ psql_completion(const char *text, int start, int end) ...@@ -1395,43 +1410,43 @@ psql_completion(const char *text, int start, int end)
} }
/* complete ALTER USER,ROLE <name> ENCRYPTED,UNENCRYPTED with PASSWORD */ /* complete ALTER USER,ROLE <name> ENCRYPTED,UNENCRYPTED with PASSWORD */
else if (TailMatches4("ALTER", "USER|ROLE", MatchAny, "ENCRYPTED|UNENCRYPTED")) else if (Matches4("ALTER", "USER|ROLE", MatchAny, "ENCRYPTED|UNENCRYPTED"))
COMPLETE_WITH_CONST("PASSWORD"); COMPLETE_WITH_CONST("PASSWORD");
/* ALTER DEFAULT PRIVILEGES */ /* ALTER DEFAULT PRIVILEGES */
else if (TailMatches3("ALTER", "DEFAULT", "PRIVILEGES")) else if (Matches3("ALTER", "DEFAULT", "PRIVILEGES"))
COMPLETE_WITH_LIST3("FOR ROLE", "FOR USER", "IN SCHEMA"); COMPLETE_WITH_LIST3("FOR ROLE", "FOR USER", "IN SCHEMA");
/* ALTER DEFAULT PRIVILEGES FOR */ /* ALTER DEFAULT PRIVILEGES FOR */
else if (TailMatches4("ALTER", "DEFAULT", "PRIVILEGES", "FOR")) else if (Matches4("ALTER", "DEFAULT", "PRIVILEGES", "FOR"))
COMPLETE_WITH_LIST2("ROLE", "USER"); COMPLETE_WITH_LIST2("ROLE", "USER");
/* ALTER DEFAULT PRIVILEGES { FOR ROLE ... | IN SCHEMA ... } */ /* ALTER DEFAULT PRIVILEGES { FOR ROLE ... | IN SCHEMA ... } */
else if (TailMatches5("DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER", MatchAny) || else if (Matches6("ALTER", "DEFAULT", "PRIVILEGES", "FOR", "ROLE|USER", MatchAny) ||
TailMatches5("DEFAULT", "PRIVILEGES", "IN", "SCHEMA", MatchAny)) Matches6("ALTER", "DEFAULT", "PRIVILEGES", "IN", "SCHEMA", MatchAny))
COMPLETE_WITH_LIST2("GRANT", "REVOKE"); COMPLETE_WITH_LIST2("GRANT", "REVOKE");
/* ALTER DOMAIN <name> */ /* ALTER DOMAIN <name> */
else if (TailMatches3("ALTER", "DOMAIN", MatchAny)) else if (Matches3("ALTER", "DOMAIN", MatchAny))
COMPLETE_WITH_LIST6("ADD", "DROP", "OWNER TO", "RENAME", "SET", COMPLETE_WITH_LIST6("ADD", "DROP", "OWNER TO", "RENAME", "SET",
"VALIDATE CONSTRAINT"); "VALIDATE CONSTRAINT");
/* ALTER DOMAIN <sth> DROP */ /* ALTER DOMAIN <sth> DROP */
else if (TailMatches4("ALTER", "DOMAIN", MatchAny, "DROP")) else if (Matches4("ALTER", "DOMAIN", MatchAny, "DROP"))
COMPLETE_WITH_LIST3("CONSTRAINT", "DEFAULT", "NOT NULL"); COMPLETE_WITH_LIST3("CONSTRAINT", "DEFAULT", "NOT NULL");
/* ALTER DOMAIN <sth> DROP|RENAME|VALIDATE CONSTRAINT */ /* ALTER DOMAIN <sth> DROP|RENAME|VALIDATE CONSTRAINT */
else if (TailMatches5("ALTER", "DOMAIN", MatchAny, "DROP|RENAME|VALIDATE", "CONSTRAINT")) else if (Matches5("ALTER", "DOMAIN", MatchAny, "DROP|RENAME|VALIDATE", "CONSTRAINT"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_constraint_of_type); COMPLETE_WITH_QUERY(Query_for_constraint_of_type);
} }
/* ALTER DOMAIN <sth> RENAME */ /* ALTER DOMAIN <sth> RENAME */
else if (TailMatches4("ALTER", "DOMAIN", MatchAny, "RENAME")) else if (Matches4("ALTER", "DOMAIN", MatchAny, "RENAME"))
COMPLETE_WITH_LIST2("CONSTRAINT", "TO"); COMPLETE_WITH_LIST2("CONSTRAINT", "TO");
/* ALTER DOMAIN <sth> RENAME CONSTRAINT <sth> */ /* ALTER DOMAIN <sth> RENAME CONSTRAINT <sth> */
else if (TailMatches5("DOMAIN", MatchAny, "RENAME", "CONSTRAINT", MatchAny)) else if (Matches6("ALTER", "DOMAIN", MatchAny, "RENAME", "CONSTRAINT", MatchAny))
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
/* ALTER DOMAIN <sth> SET */ /* ALTER DOMAIN <sth> SET */
else if (TailMatches4("ALTER", "DOMAIN", MatchAny, "SET")) else if (Matches4("ALTER", "DOMAIN", MatchAny, "SET"))
COMPLETE_WITH_LIST3("DEFAULT", "NOT NULL", "SCHEMA"); COMPLETE_WITH_LIST3("DEFAULT", "NOT NULL", "SCHEMA");
/* ALTER SEQUENCE <name> */ /* ALTER SEQUENCE <name> */
else if (TailMatches3("ALTER", "SEQUENCE", MatchAny)) else if (Matches3("ALTER", "SEQUENCE", MatchAny))
{ {
static const char *const list_ALTERSEQUENCE[] = static const char *const list_ALTERSEQUENCE[] =
{"INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", "NO", "CACHE", "CYCLE", {"INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", "NO", "CACHE", "CYCLE",
...@@ -1440,71 +1455,71 @@ psql_completion(const char *text, int start, int end) ...@@ -1440,71 +1455,71 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTERSEQUENCE); COMPLETE_WITH_LIST(list_ALTERSEQUENCE);
} }
/* ALTER SEQUENCE <name> NO */ /* ALTER SEQUENCE <name> NO */
else if (TailMatches4("ALTER", "SEQUENCE", MatchAny, "NO")) else if (Matches4("ALTER", "SEQUENCE", MatchAny, "NO"))
COMPLETE_WITH_LIST3("MINVALUE", "MAXVALUE", "CYCLE"); COMPLETE_WITH_LIST3("MINVALUE", "MAXVALUE", "CYCLE");
/* ALTER SERVER <name> */ /* ALTER SERVER <name> */
else if (TailMatches3("ALTER", "SERVER", MatchAny)) else if (Matches3("ALTER", "SERVER", MatchAny))
COMPLETE_WITH_LIST3("VERSION", "OPTIONS", "OWNER TO"); COMPLETE_WITH_LIST3("VERSION", "OPTIONS", "OWNER TO");
/* ALTER SYSTEM SET, RESET, RESET ALL */ /* ALTER SYSTEM SET, RESET, RESET ALL */
else if (TailMatches2("ALTER", "SYSTEM")) else if (Matches2("ALTER", "SYSTEM"))
COMPLETE_WITH_LIST2("SET", "RESET"); COMPLETE_WITH_LIST2("SET", "RESET");
/* ALTER SYSTEM SET|RESET <name> */ /* ALTER SYSTEM SET|RESET <name> */
else if (TailMatches4("ALTER", "SYSTEM", "SET|RESET", MatchAny)) else if (Matches4("ALTER", "SYSTEM", "SET|RESET", MatchAny))
COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars); COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars);
/* ALTER VIEW <name> */ /* ALTER VIEW <name> */
else if (TailMatches3("ALTER", "VIEW", MatchAny)) else if (Matches3("ALTER", "VIEW", MatchAny))
COMPLETE_WITH_LIST4("ALTER COLUMN", "OWNER TO", "RENAME TO", COMPLETE_WITH_LIST4("ALTER COLUMN", "OWNER TO", "RENAME TO",
"SET SCHEMA"); "SET SCHEMA");
/* ALTER MATERIALIZED VIEW <name> */ /* ALTER MATERIALIZED VIEW <name> */
else if (TailMatches4("ALTER", "MATERIALIZED", "VIEW", MatchAny)) else if (Matches4("ALTER", "MATERIALIZED", "VIEW", MatchAny))
COMPLETE_WITH_LIST4("ALTER COLUMN", "OWNER TO", "RENAME TO", COMPLETE_WITH_LIST4("ALTER COLUMN", "OWNER TO", "RENAME TO",
"SET SCHEMA"); "SET SCHEMA");
/* ALTER POLICY <name> */ /* ALTER POLICY <name> */
else if (TailMatches2("ALTER", "POLICY")) else if (Matches2("ALTER", "POLICY"))
COMPLETE_WITH_QUERY(Query_for_list_of_policies); COMPLETE_WITH_QUERY(Query_for_list_of_policies);
/* ALTER POLICY <name> ON */ /* ALTER POLICY <name> ON */
else if (TailMatches3("ALTER", "POLICY", MatchAny)) else if (Matches3("ALTER", "POLICY", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* ALTER POLICY <name> ON <table> */ /* ALTER POLICY <name> ON <table> */
else if (TailMatches4("ALTER", "POLICY", MatchAny, "ON")) else if (Matches4("ALTER", "POLICY", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy);
} }
/* ALTER POLICY <name> ON <table> - show options */ /* ALTER POLICY <name> ON <table> - show options */
else if (TailMatches5("ALTER", "POLICY", MatchAny, "ON", MatchAny)) else if (Matches5("ALTER", "POLICY", MatchAny, "ON", MatchAny))
COMPLETE_WITH_LIST4("RENAME TO", "TO", "USING", "WITH CHECK"); COMPLETE_WITH_LIST4("RENAME TO", "TO", "USING (", "WITH CHECK (");
/* ALTER POLICY <name> ON <table> TO <role> */ /* ALTER POLICY <name> ON <table> TO <role> */
else if (TailMatches6("ALTER", "POLICY", MatchAny, "ON", MatchAny, "TO")) else if (Matches6("ALTER", "POLICY", MatchAny, "ON", MatchAny, "TO"))
COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles); COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
/* ALTER POLICY <name> ON <table> USING ( */ /* ALTER POLICY <name> ON <table> USING ( */
else if (TailMatches6("ALTER", "POLICY", MatchAny, "ON", MatchAny, "USING")) else if (Matches6("ALTER", "POLICY", MatchAny, "ON", MatchAny, "USING"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER POLICY <name> ON <table> WITH CHECK ( */ /* ALTER POLICY <name> ON <table> WITH CHECK ( */
else if (TailMatches6("POLICY", MatchAny, "ON", MatchAny, "WITH", "CHECK")) else if (Matches7("ALTER", "POLICY", MatchAny, "ON", MatchAny, "WITH", "CHECK"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER RULE <name>, add ON */ /* ALTER RULE <name>, add ON */
else if (TailMatches3("ALTER", "RULE", MatchAny)) else if (Matches3("ALTER", "RULE", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* If we have ALTER RULE <name> ON, then add the correct tablename */ /* If we have ALTER RULE <name> ON, then add the correct tablename */
else if (TailMatches4("ALTER", "RULE", MatchAny, "ON")) else if (Matches4("ALTER", "RULE", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule);
} }
/* ALTER RULE <name> ON <name> */ /* ALTER RULE <name> ON <name> */
else if (TailMatches5("ALTER", "RULE", MatchAny, "ON", MatchAny)) else if (Matches5("ALTER", "RULE", MatchAny, "ON", MatchAny))
COMPLETE_WITH_CONST("RENAME TO"); COMPLETE_WITH_CONST("RENAME TO");
/* ALTER TRIGGER <name>, add ON */ /* ALTER TRIGGER <name>, add ON */
else if (TailMatches3("ALTER", "TRIGGER", MatchAny)) else if (Matches3("ALTER", "TRIGGER", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches4("ALTER", "TRIGGER", MatchAny, MatchAny)) else if (Matches4("ALTER", "TRIGGER", MatchAny, MatchAny))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
...@@ -1513,17 +1528,17 @@ psql_completion(const char *text, int start, int end) ...@@ -1513,17 +1528,17 @@ psql_completion(const char *text, int start, int end)
/* /*
* If we have ALTER TRIGGER <sth> ON, then add the correct tablename * If we have ALTER TRIGGER <sth> ON, then add the correct tablename
*/ */
else if (TailMatches4("ALTER", "TRIGGER", MatchAny, "ON")) else if (Matches4("ALTER", "TRIGGER", MatchAny, "ON"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* ALTER TRIGGER <name> ON <name> */ /* ALTER TRIGGER <name> ON <name> */
else if (TailMatches5("ALTER", "TRIGGER", MatchAny, "ON", MatchAny)) else if (Matches5("ALTER", "TRIGGER", MatchAny, "ON", MatchAny))
COMPLETE_WITH_CONST("RENAME TO"); COMPLETE_WITH_CONST("RENAME TO");
/* /*
* If we detect ALTER TABLE <name>, suggest sub commands * If we detect ALTER TABLE <name>, suggest sub commands
*/ */
else if (TailMatches3("ALTER", "TABLE", MatchAny)) else if (Matches3("ALTER", "TABLE", MatchAny))
{ {
static const char *const list_ALTER2[] = static const char *const list_ALTER2[] =
{"ADD", "ALTER", "CLUSTER ON", "DISABLE", "DROP", "ENABLE", "INHERIT", {"ADD", "ALTER", "CLUSTER ON", "DISABLE", "DROP", "ENABLE", "INHERIT",
...@@ -1533,134 +1548,131 @@ psql_completion(const char *text, int start, int end) ...@@ -1533,134 +1548,131 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_ALTER2); COMPLETE_WITH_LIST(list_ALTER2);
} }
/* ALTER TABLE xxx ENABLE */ /* ALTER TABLE xxx ENABLE */
else if (TailMatches4("ALTER", "TABLE", MatchAny, "ENABLE")) else if (Matches4("ALTER", "TABLE", MatchAny, "ENABLE"))
COMPLETE_WITH_LIST5("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE", COMPLETE_WITH_LIST5("ALWAYS", "REPLICA", "ROW LEVEL SECURITY", "RULE",
"TRIGGER"); "TRIGGER");
else if (TailMatches4("TABLE", MatchAny, "ENABLE", "REPLICA|ALWAYS")) else if (Matches5("ALTER", "TABLE", MatchAny, "ENABLE", "REPLICA|ALWAYS"))
COMPLETE_WITH_LIST2("RULE", "TRIGGER"); COMPLETE_WITH_LIST2("RULE", "TRIGGER");
else if (TailMatches5("ALTER", "TABLE", MatchAny, "ENABLE", "RULE")) else if (Matches5("ALTER", "TABLE", MatchAny, "ENABLE", "RULE"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_rule_of_table); COMPLETE_WITH_QUERY(Query_for_rule_of_table);
} }
else if (TailMatches6("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "RULE")) else if (Matches6("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "RULE"))
{ {
completion_info_charp = prev4_wd; completion_info_charp = prev4_wd;
COMPLETE_WITH_QUERY(Query_for_rule_of_table); COMPLETE_WITH_QUERY(Query_for_rule_of_table);
} }
else if (TailMatches5("ALTER", "TABLE", MatchAny, "ENABLE", "TRIGGER")) else if (Matches5("ALTER", "TABLE", MatchAny, "ENABLE", "TRIGGER"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_trigger_of_table); COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
} }
else if (TailMatches6("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "TRIGGER")) else if (Matches6("ALTER", "TABLE", MatchAny, "ENABLE", MatchAny, "TRIGGER"))
{ {
completion_info_charp = prev4_wd; completion_info_charp = prev4_wd;
COMPLETE_WITH_QUERY(Query_for_trigger_of_table); COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
} }
/* ALTER TABLE xxx INHERIT */ /* ALTER TABLE xxx INHERIT */
else if (TailMatches4("ALTER", "TABLE", MatchAny, "INHERIT")) else if (Matches4("ALTER", "TABLE", MatchAny, "INHERIT"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, ""); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, "");
/* ALTER TABLE xxx NO INHERIT */ /* ALTER TABLE xxx NO INHERIT */
else if (TailMatches5("ALTER", "TABLE", MatchAny, "NO", "INHERIT")) else if (Matches5("ALTER", "TABLE", MatchAny, "NO", "INHERIT"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, ""); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, "");
/* ALTER TABLE xxx DISABLE */ /* ALTER TABLE xxx DISABLE */
else if (TailMatches4("ALTER", "TABLE", MatchAny, "DISABLE")) else if (Matches4("ALTER", "TABLE", MatchAny, "DISABLE"))
COMPLETE_WITH_LIST3("ROW LEVEL SECURITY", "RULE", "TRIGGER"); COMPLETE_WITH_LIST3("ROW LEVEL SECURITY", "RULE", "TRIGGER");
else if (TailMatches5("ALTER", "TABLE", MatchAny, "DISABLE", "RULE")) else if (Matches5("ALTER", "TABLE", MatchAny, "DISABLE", "RULE"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_rule_of_table); COMPLETE_WITH_QUERY(Query_for_rule_of_table);
} }
else if (TailMatches5("ALTER", "TABLE", MatchAny, "DISABLE", "TRIGGER")) else if (Matches5("ALTER", "TABLE", MatchAny, "DISABLE", "TRIGGER"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_trigger_of_table); COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
} }
else if (TailMatches4("DISABLE", "ROW", "LEVEL", "SECURITY"))
COMPLETE_WITH_CONST("CASCADE");
/* ALTER TABLE xxx ALTER */ /* ALTER TABLE xxx ALTER */
else if (TailMatches4("ALTER", "TABLE", MatchAny, "ALTER")) else if (Matches4("ALTER", "TABLE", MatchAny, "ALTER"))
COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'CONSTRAINT'"); COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'CONSTRAINT'");
/* ALTER TABLE xxx RENAME */ /* ALTER TABLE xxx RENAME */
else if (TailMatches4("ALTER", "TABLE", MatchAny, "RENAME")) else if (Matches4("ALTER", "TABLE", MatchAny, "RENAME"))
COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'CONSTRAINT' UNION SELECT 'TO'"); COMPLETE_WITH_ATTR(prev2_wd, " UNION SELECT 'COLUMN' UNION SELECT 'CONSTRAINT' UNION SELECT 'TO'");
else if (Matches5("ALTER", "TABLE", MatchAny, "ALTER|RENAME", "COLUMN"))
/*
* If we have TABLE <sth> ALTER COLUMN|RENAME COLUMN, provide list of
* columns
*/
else if (TailMatches4("TABLE", MatchAny, "ALTER|RENAME", "COLUMN"))
COMPLETE_WITH_ATTR(prev3_wd, ""); COMPLETE_WITH_ATTR(prev3_wd, "");
/* ALTER TABLE xxx RENAME yyy */ /* ALTER TABLE xxx RENAME yyy */
else if (TailMatches5("ALTER", "TABLE", MatchAny, "RENAME", MatchAnyExcept("CONSTRAINT|TO"))) else if (Matches5("ALTER", "TABLE", MatchAny, "RENAME", MatchAnyExcept("CONSTRAINT|TO")))
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
/* ALTER TABLE xxx RENAME COLUMN/CONSTRAINT yyy */ /* ALTER TABLE xxx RENAME COLUMN/CONSTRAINT yyy */
else if (TailMatches5("TABLE", MatchAny, "RENAME", "COLUMN|CONSTRAINT", MatchAnyExcept("TO"))) else if (Matches6("ALTER", "TABLE", MatchAny, "RENAME", "COLUMN|CONSTRAINT", MatchAnyExcept("TO")))
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
/* If we have TABLE <sth> DROP, provide COLUMN or CONSTRAINT */ /* If we have ALTER TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
else if (TailMatches3("TABLE", MatchAny, "DROP")) else if (Matches4("ALTER", "TABLE", MatchAny, "DROP"))
COMPLETE_WITH_LIST2("COLUMN", "CONSTRAINT"); COMPLETE_WITH_LIST2("COLUMN", "CONSTRAINT");
/* If we have ALTER TABLE <sth> DROP COLUMN, provide list of columns */ /* If we have ALTER TABLE <sth> DROP COLUMN, provide list of columns */
else if (TailMatches5("ALTER", "TABLE", MatchAny, "DROP", "COLUMN")) else if (Matches5("ALTER", "TABLE", MatchAny, "DROP", "COLUMN"))
COMPLETE_WITH_ATTR(prev3_wd, ""); COMPLETE_WITH_ATTR(prev3_wd, "");
/* /*
* If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE CONSTRAINT, * If we have ALTER TABLE <sth> ALTER|DROP|RENAME|VALIDATE CONSTRAINT,
* provide list of constraints * provide list of constraints
*/ */
else if (TailMatches5("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT")) else if (Matches5("ALTER", "TABLE", MatchAny, "ALTER|DROP|RENAME|VALIDATE", "CONSTRAINT"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_constraint_of_table); COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
} }
/* ALTER TABLE ALTER [COLUMN] <foo> */ /* ALTER TABLE ALTER [COLUMN] <foo> */
else if (TailMatches3("ALTER", "COLUMN", MatchAny) || else if (Matches6("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny) ||
TailMatches4("TABLE", MatchAny, "ALTER", MatchAny)) Matches5("ALTER", "TABLE", MatchAny, "ALTER", MatchAny))
COMPLETE_WITH_LIST4("TYPE", "SET", "RESET", "DROP"); COMPLETE_WITH_LIST4("TYPE", "SET", "RESET", "DROP");
/* ALTER TABLE ALTER [COLUMN] <foo> SET */ /* ALTER TABLE ALTER [COLUMN] <foo> SET */
else if (TailMatches4("ALTER", "COLUMN", MatchAny, "SET") || else if (Matches7("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET") ||
TailMatches5("TABLE", MatchAny, "ALTER", MatchAny, "SET")) Matches6("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET"))
COMPLETE_WITH_LIST5("(", "DEFAULT", "NOT NULL", "STATISTICS", "STORAGE"); COMPLETE_WITH_LIST5("(", "DEFAULT", "NOT NULL", "STATISTICS", "STORAGE");
/* ALTER TABLE ALTER [COLUMN] <foo> SET ( */ /* ALTER TABLE ALTER [COLUMN] <foo> SET ( */
else if (TailMatches5("ALTER", "COLUMN", MatchAny, "SET", "(") || else if (Matches8("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "(") ||
TailMatches4("ALTER", MatchAny, "SET", "(")) Matches7("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "("))
COMPLETE_WITH_LIST2("n_distinct", "n_distinct_inherited"); COMPLETE_WITH_LIST2("n_distinct", "n_distinct_inherited");
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */ /* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */
else if (TailMatches5("ALTER", "COLUMN", MatchAny, "SET", "STORAGE") || else if (Matches8("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "SET", "STORAGE") ||
TailMatches4("ALTER", MatchAny, "SET", "STORAGE")) Matches7("ALTER", "TABLE", MatchAny, "ALTER", MatchAny, "SET", "STORAGE"))
COMPLETE_WITH_LIST4("PLAIN", "EXTERNAL", "EXTENDED", "MAIN"); COMPLETE_WITH_LIST4("PLAIN", "EXTERNAL", "EXTENDED", "MAIN");
/* ALTER TABLE ALTER [COLUMN] <foo> DROP */ /* ALTER TABLE ALTER [COLUMN] <foo> DROP */
else if (TailMatches4("ALTER", "COLUMN", MatchAny, "DROP") || else if (Matches7("ALTER", "TABLE", MatchAny, "ALTER", "COLUMN", MatchAny, "DROP") ||
TailMatches5("TABLE", MatchAny, "ALTER", MatchAny, "DROP")) Matches8("ALTER", "TABLE", MatchAny, "TABLE", MatchAny, "ALTER", MatchAny, "DROP"))
COMPLETE_WITH_LIST2("DEFAULT", "NOT NULL"); COMPLETE_WITH_LIST2("DEFAULT", "NOT NULL");
else if (TailMatches3("TABLE", MatchAny, "CLUSTER")) else if (Matches4("ALTER", "TABLE", MatchAny, "CLUSTER"))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches4("TABLE", MatchAny, "CLUSTER", "ON")) else if (Matches5("ALTER", "TABLE", MatchAny, "CLUSTER", "ON"))
{ {
completion_info_charp = prev3_wd; completion_info_charp = prev3_wd;
COMPLETE_WITH_QUERY(Query_for_index_of_table); COMPLETE_WITH_QUERY(Query_for_index_of_table);
} }
/* If we have TABLE <sth> SET, provide list of attributes and '(' */ /* If we have ALTER TABLE <sth> SET, provide list of attributes and '(' */
else if (TailMatches3("TABLE", MatchAny, "SET")) else if (Matches4("ALTER", "TABLE", MatchAny, "SET"))
COMPLETE_WITH_LIST7("(", "LOGGED", "SCHEMA", "TABLESPACE", "UNLOGGED", COMPLETE_WITH_LIST7("(", "LOGGED", "SCHEMA", "TABLESPACE", "UNLOGGED",
"WITH", "WITHOUT"); "WITH", "WITHOUT");
/* If we have TABLE <sth> SET TABLESPACE provide a list of tablespaces */
else if (TailMatches4("TABLE", MatchAny, "SET", "TABLESPACE")) /*
* If we have ALTER TABLE <sth> SET TABLESPACE provide a list of
* tablespaces
*/
else if (Matches5("ALTER", "TABLE", MatchAny, "SET", "TABLESPACE"))
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces); COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
/* If we have TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */ /* If we have ALTER TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */
else if (TailMatches4("TABLE", MatchAny, "SET", "WITHOUT")) else if (Matches5("ALTER", "TABLE", MatchAny, "SET", "WITHOUT"))
COMPLETE_WITH_LIST2("CLUSTER", "OIDS"); COMPLETE_WITH_LIST2("CLUSTER", "OIDS");
/* ALTER TABLE <foo> RESET */ /* ALTER TABLE <foo> RESET */
else if (TailMatches3("TABLE", MatchAny, "RESET")) else if (Matches4("ALTER", "TABLE", MatchAny, "RESET"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER TABLE <foo> SET|RESET ( */ /* ALTER TABLE <foo> SET|RESET ( */
else if (TailMatches4("TABLE", MatchAny, "SET|RESET", "(")) else if (Matches5("ALTER", "TABLE", MatchAny, "SET|RESET", "("))
{ {
static const char *const list_TABLEOPTIONS[] = static const char *const list_TABLEOPTIONS[] =
{ {
...@@ -1697,130 +1709,110 @@ psql_completion(const char *text, int start, int end) ...@@ -1697,130 +1709,110 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_TABLEOPTIONS); COMPLETE_WITH_LIST(list_TABLEOPTIONS);
} }
else if (TailMatches5(MatchAny, "REPLICA", "IDENTITY", "USING", "INDEX")) else if (Matches7("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY", "USING", "INDEX"))
{ {
completion_info_charp = prev5_wd; completion_info_charp = prev5_wd;
COMPLETE_WITH_QUERY(Query_for_index_of_table); COMPLETE_WITH_QUERY(Query_for_index_of_table);
} }
else if (TailMatches5("TABLE", MatchAny, "REPLICA", "IDENTITY", "USING")) else if (Matches6("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY", "USING"))
COMPLETE_WITH_CONST("INDEX"); COMPLETE_WITH_CONST("INDEX");
else if (TailMatches4("TABLE", MatchAny, "REPLICA", "IDENTITY")) else if (Matches5("ALTER", "TABLE", MatchAny, "REPLICA", "IDENTITY"))
COMPLETE_WITH_LIST4("FULL", "NOTHING", "DEFAULT", "USING"); COMPLETE_WITH_LIST4("FULL", "NOTHING", "DEFAULT", "USING");
else if (TailMatches3("TABLE", MatchAny, "REPLICA")) else if (Matches4("ALTER", "TABLE", MatchAny, "REPLICA"))
COMPLETE_WITH_CONST("IDENTITY"); COMPLETE_WITH_CONST("IDENTITY");
/* ALTER TABLESPACE <foo> with RENAME TO, OWNER TO, SET, RESET */ /* ALTER TABLESPACE <foo> with RENAME TO, OWNER TO, SET, RESET */
else if (TailMatches3("ALTER", "TABLESPACE", MatchAny)) else if (Matches3("ALTER", "TABLESPACE", MatchAny))
COMPLETE_WITH_LIST4("RENAME TO", "OWNER TO", "SET", "RESET"); COMPLETE_WITH_LIST4("RENAME TO", "OWNER TO", "SET", "RESET");
/* ALTER TABLESPACE <foo> SET|RESET */ /* ALTER TABLESPACE <foo> SET|RESET */
else if (TailMatches4("ALTER", "TABLESPACE", MatchAny, "SET|RESET")) else if (Matches4("ALTER", "TABLESPACE", MatchAny, "SET|RESET"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* ALTER TABLESPACE <foo> SET|RESET ( */ /* ALTER TABLESPACE <foo> SET|RESET ( */
else if (TailMatches5("ALTER", "TABLESPACE", MatchAny, "SET|RESET", "(")) else if (Matches5("ALTER", "TABLESPACE", MatchAny, "SET|RESET", "("))
COMPLETE_WITH_LIST3("seq_page_cost", "random_page_cost", COMPLETE_WITH_LIST3("seq_page_cost", "random_page_cost",
"effective_io_concurrency"); "effective_io_concurrency");
/* ALTER TEXT SEARCH */ /* ALTER TEXT SEARCH */
else if (TailMatches3("ALTER", "TEXT", "SEARCH")) else if (Matches3("ALTER", "TEXT", "SEARCH"))
COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE");
else if (TailMatches5("ALTER", "TEXT", "SEARCH", "TEMPLATE|PARSER", MatchAny)) else if (Matches5("ALTER", "TEXT", "SEARCH", "TEMPLATE|PARSER", MatchAny))
COMPLETE_WITH_LIST2("RENAME TO", "SET SCHEMA"); COMPLETE_WITH_LIST2("RENAME TO", "SET SCHEMA");
else if (TailMatches5("ALTER", "TEXT", "SEARCH", "DICTIONARY", MatchAny)) else if (Matches5("ALTER", "TEXT", "SEARCH", "DICTIONARY", MatchAny))
COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA"); COMPLETE_WITH_LIST3("OWNER TO", "RENAME TO", "SET SCHEMA");
else if (TailMatches5("ALTER", "TEXT", "SEARCH", "CONFIGURATION", MatchAny)) else if (Matches5("ALTER", "TEXT", "SEARCH", "CONFIGURATION", MatchAny))
COMPLETE_WITH_LIST6("ADD MAPPING FOR", "ALTER MAPPING", COMPLETE_WITH_LIST6("ADD MAPPING FOR", "ALTER MAPPING",
"DROP MAPPING FOR", "DROP MAPPING FOR",
"OWNER TO", "RENAME TO", "SET SCHEMA"); "OWNER TO", "RENAME TO", "SET SCHEMA");
/* complete ALTER TYPE <foo> with actions */ /* complete ALTER TYPE <foo> with actions */
else if (TailMatches3("ALTER", "TYPE", MatchAny)) else if (Matches3("ALTER", "TYPE", MatchAny))
COMPLETE_WITH_LIST7("ADD ATTRIBUTE", "ADD VALUE", "ALTER ATTRIBUTE", COMPLETE_WITH_LIST7("ADD ATTRIBUTE", "ADD VALUE", "ALTER ATTRIBUTE",
"DROP ATTRIBUTE", "DROP ATTRIBUTE",
"OWNER TO", "RENAME", "SET SCHEMA"); "OWNER TO", "RENAME", "SET SCHEMA");
/* complete ALTER TYPE <foo> ADD with actions */ /* complete ALTER TYPE <foo> ADD with actions */
else if (TailMatches4("ALTER", "TYPE", MatchAny, "ADD")) else if (Matches4("ALTER", "TYPE", MatchAny, "ADD"))
COMPLETE_WITH_LIST2("ATTRIBUTE", "VALUE"); COMPLETE_WITH_LIST2("ATTRIBUTE", "VALUE");
/* ALTER TYPE <foo> RENAME */ /* ALTER TYPE <foo> RENAME */
else if (TailMatches4("ALTER", "TYPE", MatchAny, "RENAME")) else if (Matches4("ALTER", "TYPE", MatchAny, "RENAME"))
COMPLETE_WITH_LIST2("ATTRIBUTE", "TO"); COMPLETE_WITH_LIST2("ATTRIBUTE", "TO");
/* ALTER TYPE xxx RENAME ATTRIBUTE yyy */ /* ALTER TYPE xxx RENAME ATTRIBUTE yyy */
else if (TailMatches5("TYPE", MatchAny, "RENAME", "ATTRIBUTE", MatchAny)) else if (Matches6("ALTER", "TYPE", MatchAny, "RENAME", "ATTRIBUTE", MatchAny))
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
/* /*
* If we have TYPE <sth> ALTER/DROP/RENAME ATTRIBUTE, provide list of * If we have ALTER TYPE <sth> ALTER/DROP/RENAME ATTRIBUTE, provide list
* attributes * of attributes
*/ */
else if (TailMatches4("TYPE", MatchAny, "ALTER|DROP|RENAME", "ATTRIBUTE")) else if (Matches5("ALTER", "TYPE", MatchAny, "ALTER|DROP|RENAME", "ATTRIBUTE"))
COMPLETE_WITH_ATTR(prev3_wd, ""); COMPLETE_WITH_ATTR(prev3_wd, "");
/* ALTER TYPE ALTER ATTRIBUTE <foo> */ /* ALTER TYPE ALTER ATTRIBUTE <foo> */
else if (TailMatches3("ALTER", "ATTRIBUTE", MatchAny)) else if (Matches6("ALTER", "TYPE", MatchAny, "ALTER", "ATTRIBUTE", MatchAny))
COMPLETE_WITH_CONST("TYPE"); COMPLETE_WITH_CONST("TYPE");
/* complete ALTER GROUP <foo> */ /* complete ALTER GROUP <foo> */
else if (TailMatches3("ALTER", "GROUP", MatchAny)) else if (Matches3("ALTER", "GROUP", MatchAny))
COMPLETE_WITH_LIST3("ADD USER", "DROP USER", "RENAME TO"); COMPLETE_WITH_LIST3("ADD USER", "DROP USER", "RENAME TO");
/* complete ALTER GROUP <foo> ADD|DROP with USER */ /* complete ALTER GROUP <foo> ADD|DROP with USER */
else if (TailMatches4("ALTER", "GROUP", MatchAny, "ADD|DROP")) else if (Matches4("ALTER", "GROUP", MatchAny, "ADD|DROP"))
COMPLETE_WITH_CONST("USER"); COMPLETE_WITH_CONST("USER");
/* complete ALTER GROUP <foo> ADD|DROP USER with a user name */ /* complete ALTER GROUP <foo> ADD|DROP USER with a user name */
else if (TailMatches5("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER")) else if (Matches5("ALTER", "GROUP", MatchAny, "ADD|DROP", "USER"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
/* BEGIN, END, ABORT */ /* BEGIN, END, ABORT */
else if (TailMatches1("BEGIN|END|ABORT")) else if (Matches1("BEGIN|END|ABORT"))
COMPLETE_WITH_LIST2("WORK", "TRANSACTION"); COMPLETE_WITH_LIST2("WORK", "TRANSACTION");
/* COMMIT */ /* COMMIT */
else if (TailMatches1("COMMIT")) else if (Matches1("COMMIT"))
COMPLETE_WITH_LIST3("WORK", "TRANSACTION", "PREPARED"); COMPLETE_WITH_LIST3("WORK", "TRANSACTION", "PREPARED");
/* RELEASE SAVEPOINT */ /* RELEASE SAVEPOINT */
else if (TailMatches1("RELEASE")) else if (Matches1("RELEASE"))
COMPLETE_WITH_CONST("SAVEPOINT"); COMPLETE_WITH_CONST("SAVEPOINT");
/* ROLLBACK*/ /* ROLLBACK */
else if (TailMatches1("ROLLBACK")) else if (Matches1("ROLLBACK"))
COMPLETE_WITH_LIST4("WORK", "TRANSACTION", "TO SAVEPOINT", "PREPARED"); COMPLETE_WITH_LIST4("WORK", "TRANSACTION", "TO SAVEPOINT", "PREPARED");
/* CLUSTER */ /* CLUSTER */
else if (Matches1("CLUSTER"))
/*
* If the previous word is CLUSTER and not WITHOUT produce list of tables
*/
else if (TailMatches1("CLUSTER") && !TailMatches2("WITHOUT", "CLUSTER"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, "UNION SELECT 'VERBOSE'"); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, "UNION SELECT 'VERBOSE'");
else if (Matches2("CLUSTER", "VERBOSE"))
/*
* If the previous words are CLUSTER VERBOSE produce list of tables
*/
else if (TailMatches2("CLUSTER", "VERBOSE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL);
/* If we have CLUSTER <sth>, then add "USING" */ /* If we have CLUSTER <sth>, then add "USING" */
else if (TailMatches2("CLUSTER", MatchAnyExcept("VERBOSE|ON"))) else if (Matches2("CLUSTER", MatchAnyExcept("VERBOSE|ON")))
COMPLETE_WITH_CONST("USING"); COMPLETE_WITH_CONST("USING");
/* If we have CLUSTER VERBOSE <sth>, then add "USING" */ /* If we have CLUSTER VERBOSE <sth>, then add "USING" */
else if (TailMatches3("CLUSTER", "VERBOSE", MatchAny)) else if (Matches3("CLUSTER", "VERBOSE", MatchAny))
COMPLETE_WITH_CONST("USING"); COMPLETE_WITH_CONST("USING");
/* If we have CLUSTER <sth> USING, then add the index as well */
/* else if (Matches3("CLUSTER", MatchAny, "USING") ||
* If we have CLUSTER <sth> USING, then add the index as well. Matches4("CLUSTER", "VERBOSE", MatchAny, "USING"))
*/
else if (TailMatches3("CLUSTER", MatchAny, "USING"))
{
completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_index_of_table);
}
/*
* If we have CLUSTER VERBOSE <sth> USING, then add the index as well.
*/
else if (TailMatches4("CLUSTER", "VERBOSE", MatchAny, "USING"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_index_of_table); COMPLETE_WITH_QUERY(Query_for_index_of_table);
} }
/* COMMENT */ /* COMMENT */
else if (TailMatches1("COMMENT")) else if (Matches1("COMMENT"))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches2("COMMENT", "ON")) else if (Matches2("COMMENT", "ON"))
{ {
static const char *const list_COMMENT[] = static const char *const list_COMMENT[] =
{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EVENT TRIGGER", "EXTENSION", {"CAST", "COLLATION", "CONVERSION", "DATABASE", "EVENT TRIGGER", "EXTENSION",
...@@ -1832,26 +1824,26 @@ psql_completion(const char *text, int start, int end) ...@@ -1832,26 +1824,26 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST(list_COMMENT); COMPLETE_WITH_LIST(list_COMMENT);
} }
else if (TailMatches3("COMMENT", "ON", "FOREIGN")) else if (Matches3("COMMENT", "ON", "FOREIGN"))
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE"); COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
else if (TailMatches4("COMMENT", "ON", "TEXT", "SEARCH")) else if (Matches4("COMMENT", "ON", "TEXT", "SEARCH"))
COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE");
else if (TailMatches3("COMMENT", "ON", "CONSTRAINT")) else if (Matches3("COMMENT", "ON", "CONSTRAINT"))
COMPLETE_WITH_QUERY(Query_for_all_table_constraints); COMPLETE_WITH_QUERY(Query_for_all_table_constraints);
else if (TailMatches4("COMMENT", "ON", "CONSTRAINT", MatchAny)) else if (Matches4("COMMENT", "ON", "CONSTRAINT", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches5("COMMENT", "ON", "CONSTRAINT", MatchAny, "ON")) else if (Matches5("COMMENT", "ON", "CONSTRAINT", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_constraint); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_constraint);
} }
else if (TailMatches4("COMMENT", "ON", "MATERIALIZED", "VIEW")) else if (Matches4("COMMENT", "ON", "MATERIALIZED", "VIEW"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
else if (TailMatches4("COMMENT", "ON", "EVENT", "TRIGGER")) else if (Matches4("COMMENT", "ON", "EVENT", "TRIGGER"))
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
else if (TailMatches4("COMMENT", "ON", MatchAny, MatchAnyExcept("IS")) || else if (Matches4("COMMENT", "ON", MatchAny, MatchAnyExcept("IS")) ||
TailMatches5("COMMENT", "ON", MatchAny, MatchAny, MatchAnyExcept("IS")) || Matches5("COMMENT", "ON", MatchAny, MatchAny, MatchAnyExcept("IS")) ||
TailMatches6("COMMENT", "ON", MatchAny, MatchAny, MatchAny, MatchAnyExcept("IS"))) Matches6("COMMENT", "ON", MatchAny, MatchAny, MatchAny, MatchAnyExcept("IS")))
COMPLETE_WITH_CONST("IS"); COMPLETE_WITH_CONST("IS");
/* COPY */ /* COPY */
...@@ -1860,61 +1852,65 @@ psql_completion(const char *text, int start, int end) ...@@ -1860,61 +1852,65 @@ psql_completion(const char *text, int start, int end)
* If we have COPY [BINARY] (which you'd have to type yourself), offer * If we have COPY [BINARY] (which you'd have to type yourself), offer
* list of tables (Also cover the analogous backslash command) * list of tables (Also cover the analogous backslash command)
*/ */
else if (TailMatches1("COPY|\\copy") || TailMatches2("COPY", "BINARY")) else if (Matches1("COPY|\\copy") || Matches2("COPY", "BINARY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* If we have COPY|BINARY <sth>, complete it with "TO" or "FROM" */ /* If we have COPY [BINARY] <sth>, complete it with "TO" or "FROM" */
else if (TailMatches2("COPY|\\copy|BINARY", MatchAny)) else if (Matches2("COPY|\\copy", MatchAny) ||
Matches3("COPY", "BINARY", MatchAny))
COMPLETE_WITH_LIST2("FROM", "TO"); COMPLETE_WITH_LIST2("FROM", "TO");
/* If we have COPY|BINARY <sth> FROM|TO, complete with filename */ /* If we have COPY [BINARY] <sth> FROM|TO, complete with filename */
else if (TailMatches3("COPY|\\copy|BINARY", MatchAny, "FROM|TO")) else if (Matches3("COPY|\\copy", MatchAny, "FROM|TO") ||
Matches4("COPY", "BINARY", MatchAny, "FROM|TO"))
{ {
completion_charp = ""; completion_charp = "";
matches = completion_matches(text, complete_from_files); matches = completion_matches(text, complete_from_files);
} }
/* Handle COPY|BINARY <sth> FROM|TO filename */ /* Handle COPY [BINARY] <sth> FROM|TO filename */
else if (TailMatches4("COPY|\\copy|BINARY", MatchAny, "FROM|TO", MatchAny)) else if (Matches4("COPY|\\copy", MatchAny, "FROM|TO", MatchAny) ||
Matches5("COPY", "BINARY", MatchAny, "FROM|TO", MatchAny))
COMPLETE_WITH_LIST6("BINARY", "OIDS", "DELIMITER", "NULL", "CSV", COMPLETE_WITH_LIST6("BINARY", "OIDS", "DELIMITER", "NULL", "CSV",
"ENCODING"); "ENCODING");
/* Handle COPY|BINARY <sth> FROM|TO filename CSV */ /* Handle COPY [BINARY] <sth> FROM|TO filename CSV */
else if (TailMatches3("FROM|TO", MatchAny, "CSV")) else if (Matches5("COPY|\\copy", MatchAny, "FROM|TO", MatchAny, "CSV") ||
Matches6("COPY", "BINARY", MatchAny, "FROM|TO", MatchAny, "CSV"))
COMPLETE_WITH_LIST5("HEADER", "QUOTE", "ESCAPE", "FORCE QUOTE", COMPLETE_WITH_LIST5("HEADER", "QUOTE", "ESCAPE", "FORCE QUOTE",
"FORCE NOT NULL"); "FORCE NOT NULL");
/* CREATE DATABASE */ /* CREATE DATABASE */
else if (TailMatches3("CREATE", "DATABASE", MatchAny)) else if (Matches3("CREATE", "DATABASE", MatchAny))
COMPLETE_WITH_LIST9("OWNER", "TEMPLATE", "ENCODING", "TABLESPACE", COMPLETE_WITH_LIST9("OWNER", "TEMPLATE", "ENCODING", "TABLESPACE",
"IS_TEMPLATE", "IS_TEMPLATE",
"ALLOW_CONNECTIONS", "CONNECTION LIMIT", "ALLOW_CONNECTIONS", "CONNECTION LIMIT",
"LC_COLLATE", "LC_CTYPE"); "LC_COLLATE", "LC_CTYPE");
else if (TailMatches4("CREATE", "DATABASE", MatchAny, "TEMPLATE")) else if (Matches4("CREATE", "DATABASE", MatchAny, "TEMPLATE"))
COMPLETE_WITH_QUERY(Query_for_list_of_template_databases); COMPLETE_WITH_QUERY(Query_for_list_of_template_databases);
/* CREATE EXTENSION */ /* CREATE EXTENSION */
/* Complete with available extensions rather than installed ones. */ /* Complete with available extensions rather than installed ones. */
else if (TailMatches2("CREATE", "EXTENSION")) else if (Matches2("CREATE", "EXTENSION"))
COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions); COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions);
/* CREATE EXTENSION <name> */ /* CREATE EXTENSION <name> */
else if (TailMatches3("CREATE", "EXTENSION", MatchAny)) else if (Matches3("CREATE", "EXTENSION", MatchAny))
COMPLETE_WITH_LIST3("WITH SCHEMA", "CASCADE", "VERSION"); COMPLETE_WITH_LIST3("WITH SCHEMA", "CASCADE", "VERSION");
/* CREATE EXTENSION <name> VERSION */ /* CREATE EXTENSION <name> VERSION */
else if (TailMatches4("CREATE", "EXTENSION", MatchAny, "VERSION")) else if (Matches4("CREATE", "EXTENSION", MatchAny, "VERSION"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions); COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
} }
/* CREATE FOREIGN */ /* CREATE FOREIGN */
else if (TailMatches2("CREATE", "FOREIGN")) else if (Matches2("CREATE", "FOREIGN"))
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE"); COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
/* CREATE FOREIGN DATA WRAPPER */ /* CREATE FOREIGN DATA WRAPPER */
else if (TailMatches5("CREATE", "FOREIGN", "DATA", "WRAPPER", MatchAny)) else if (Matches5("CREATE", "FOREIGN", "DATA", "WRAPPER", MatchAny))
COMPLETE_WITH_LIST2("HANDLER", "VALIDATOR"); COMPLETE_WITH_LIST2("HANDLER", "VALIDATOR");
/* CREATE INDEX */ /* CREATE INDEX --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* First off we complete CREATE UNIQUE with "INDEX" */ /* First off we complete CREATE UNIQUE with "INDEX" */
else if (TailMatches2("CREATE", "UNIQUE")) else if (TailMatches2("CREATE", "UNIQUE"))
COMPLETE_WITH_CONST("INDEX"); COMPLETE_WITH_CONST("INDEX");
...@@ -1960,42 +1956,42 @@ psql_completion(const char *text, int start, int end) ...@@ -1960,42 +1956,42 @@ psql_completion(const char *text, int start, int end)
/* CREATE POLICY */ /* CREATE POLICY */
/* Complete "CREATE POLICY <name> ON" */ /* Complete "CREATE POLICY <name> ON" */
else if (TailMatches3("CREATE", "POLICY", MatchAny)) else if (Matches3("CREATE", "POLICY", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* Complete "CREATE POLICY <name> ON <table>" */ /* Complete "CREATE POLICY <name> ON <table>" */
else if (TailMatches4("CREATE", "POLICY", MatchAny, "ON")) else if (Matches4("CREATE", "POLICY", MatchAny, "ON"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* Complete "CREATE POLICY <name> ON <table> FOR|TO|USING|WITH CHECK" */ /* Complete "CREATE POLICY <name> ON <table> FOR|TO|USING|WITH CHECK" */
else if (TailMatches5("CREATE", "POLICY", MatchAny, "ON", MatchAny)) else if (Matches5("CREATE", "POLICY", MatchAny, "ON", MatchAny))
COMPLETE_WITH_LIST4("FOR", "TO", "USING", "WITH CHECK"); COMPLETE_WITH_LIST4("FOR", "TO", "USING (", "WITH CHECK (");
/* CREATE POLICY <name> ON <table> FOR ALL|SELECT|INSERT|UPDATE|DELETE */ /* CREATE POLICY <name> ON <table> FOR ALL|SELECT|INSERT|UPDATE|DELETE */
else if (TailMatches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR")) else if (Matches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR"))
COMPLETE_WITH_LIST5("ALL", "SELECT", "INSERT", "UPDATE", "DELETE"); COMPLETE_WITH_LIST5("ALL", "SELECT", "INSERT", "UPDATE", "DELETE");
/* Complete "CREATE POLICY <name> ON <table> FOR INSERT TO|WITH CHECK" */ /* Complete "CREATE POLICY <name> ON <table> FOR INSERT TO|WITH CHECK" */
else if (TailMatches6("POLICY", MatchAny, "ON", MatchAny, "FOR", "INSERT")) else if (Matches7("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "INSERT"))
COMPLETE_WITH_LIST2("TO", "WITH CHECK"); COMPLETE_WITH_LIST2("TO", "WITH CHECK (");
/* Complete "CREATE POLICY <name> ON <table> FOR SELECT|DELETE TO|USING" */ /* Complete "CREATE POLICY <name> ON <table> FOR SELECT|DELETE TO|USING" */
else if (TailMatches6("POLICY", MatchAny, "ON", MatchAny, "FOR", "SELECT|DELETE")) else if (Matches7("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "SELECT|DELETE"))
COMPLETE_WITH_LIST2("TO", "USING"); COMPLETE_WITH_LIST2("TO", "USING (");
/* CREATE POLICY <name> ON <table> FOR ALL|UPDATE TO|USING|WITH CHECK */ /* CREATE POLICY <name> ON <table> FOR ALL|UPDATE TO|USING|WITH CHECK */
else if (TailMatches6("POLICY", MatchAny, "ON", MatchAny, "FOR", "ALL|UPDATE")) else if (Matches7("CREATE", "POLICY", MatchAny, "ON", MatchAny, "FOR", "ALL|UPDATE"))
COMPLETE_WITH_LIST3("TO", "USING", "WITH CHECK"); COMPLETE_WITH_LIST3("TO", "USING (", "WITH CHECK (");
/* Complete "CREATE POLICY <name> ON <table> TO <role>" */ /* Complete "CREATE POLICY <name> ON <table> TO <role>" */
else if (TailMatches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "TO")) else if (Matches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "TO"))
COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles); COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
/* Complete "CREATE POLICY <name> ON <table> USING (" */ /* Complete "CREATE POLICY <name> ON <table> USING (" */
else if (TailMatches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "USING")) else if (Matches6("CREATE", "POLICY", MatchAny, "ON", MatchAny, "USING"))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* CREATE RULE */ /* CREATE RULE */
/* Complete "CREATE RULE <sth>" with "AS" */ /* Complete "CREATE RULE <sth>" with "AS ON" */
else if (TailMatches3("CREATE", "RULE", MatchAny)) else if (Matches3("CREATE", "RULE", MatchAny))
COMPLETE_WITH_CONST("AS"); COMPLETE_WITH_CONST("AS ON");
/* Complete "CREATE RULE <sth> AS" with "ON" */ /* Complete "CREATE RULE <sth> AS" with "ON" */
else if (TailMatches4("CREATE", "RULE", MatchAny, "AS")) else if (Matches4("CREATE", "RULE", MatchAny, "AS"))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* Complete "RULE * AS ON" with SELECT|UPDATE|INSERT|DELETE */ /* Complete "CREATE RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
else if (TailMatches4("RULE", MatchAny, "AS", "ON")) else if (Matches5("CREATE", "RULE", MatchAny, "AS", "ON"))
COMPLETE_WITH_LIST4("SELECT", "UPDATE", "INSERT", "DELETE"); COMPLETE_WITH_LIST4("SELECT", "UPDATE", "INSERT", "DELETE");
/* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */ /* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */
else if (TailMatches3("AS", "ON", "SELECT|UPDATE|INSERT|DELETE")) else if (TailMatches3("AS", "ON", "SELECT|UPDATE|INSERT|DELETE"))
...@@ -2004,21 +2000,20 @@ psql_completion(const char *text, int start, int end) ...@@ -2004,21 +2000,20 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches4("AS", "ON", "SELECT|UPDATE|INSERT|DELETE", "TO")) else if (TailMatches4("AS", "ON", "SELECT|UPDATE|INSERT|DELETE", "TO"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* CREATE TEMP/TEMPORARY SEQUENCE <name> */ /* CREATE SEQUENCE --- is allowed inside CREATE SCHEMA, so use TailMatches */
else if (TailMatches3("CREATE", "SEQUENCE", MatchAny) || else if (TailMatches3("CREATE", "SEQUENCE", MatchAny) ||
TailMatches4("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny)) TailMatches4("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny))
COMPLETE_WITH_LIST8("INCREMENT BY", "MINVALUE", "MAXVALUE", "NO", "CACHE", COMPLETE_WITH_LIST8("INCREMENT BY", "MINVALUE", "MAXVALUE", "NO", "CACHE",
"CYCLE", "OWNED BY", "START WITH"); "CYCLE", "OWNED BY", "START WITH");
/* CREATE TEMP/TEMPORARY SEQUENCE <name> NO */
else if (TailMatches4("CREATE", "SEQUENCE", MatchAny, "NO") || else if (TailMatches4("CREATE", "SEQUENCE", MatchAny, "NO") ||
TailMatches5("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny, "NO")) TailMatches5("CREATE", "TEMP|TEMPORARY", "SEQUENCE", MatchAny, "NO"))
COMPLETE_WITH_LIST3("MINVALUE", "MAXVALUE", "CYCLE"); COMPLETE_WITH_LIST3("MINVALUE", "MAXVALUE", "CYCLE");
/* CREATE SERVER <name> */ /* CREATE SERVER <name> */
else if (TailMatches3("CREATE", "SERVER", MatchAny)) else if (Matches3("CREATE", "SERVER", MatchAny))
COMPLETE_WITH_LIST3("TYPE", "VERSION", "FOREIGN DATA WRAPPER"); COMPLETE_WITH_LIST3("TYPE", "VERSION", "FOREIGN DATA WRAPPER");
/* CREATE TABLE */ /* CREATE TABLE --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */ /* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */
else if (TailMatches2("CREATE", "TEMP|TEMPORARY")) else if (TailMatches2("CREATE", "TEMP|TEMPORARY"))
COMPLETE_WITH_LIST3("SEQUENCE", "TABLE", "VIEW"); COMPLETE_WITH_LIST3("SEQUENCE", "TABLE", "VIEW");
...@@ -2027,19 +2022,19 @@ psql_completion(const char *text, int start, int end) ...@@ -2027,19 +2022,19 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST2("TABLE", "MATERIALIZED VIEW"); COMPLETE_WITH_LIST2("TABLE", "MATERIALIZED VIEW");
/* CREATE TABLESPACE */ /* CREATE TABLESPACE */
else if (TailMatches3("CREATE", "TABLESPACE", MatchAny)) else if (Matches3("CREATE", "TABLESPACE", MatchAny))
COMPLETE_WITH_LIST2("OWNER", "LOCATION"); COMPLETE_WITH_LIST2("OWNER", "LOCATION");
/* Complete CREATE TABLESPACE name OWNER name with "LOCATION" */ /* Complete CREATE TABLESPACE name OWNER name with "LOCATION" */
else if (TailMatches5("CREATE", "TABLESPACE", MatchAny, "OWNER", MatchAny)) else if (Matches5("CREATE", "TABLESPACE", MatchAny, "OWNER", MatchAny))
COMPLETE_WITH_CONST("LOCATION"); COMPLETE_WITH_CONST("LOCATION");
/* CREATE TEXT SEARCH */ /* CREATE TEXT SEARCH */
else if (TailMatches3("CREATE", "TEXT", "SEARCH")) else if (Matches3("CREATE", "TEXT", "SEARCH"))
COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE");
else if (TailMatches4("TEXT", "SEARCH", "CONFIGURATION", MatchAny)) else if (Matches5("CREATE", "TEXT", "SEARCH", "CONFIGURATION", MatchAny))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* CREATE TRIGGER */ /* CREATE TRIGGER --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* complete CREATE TRIGGER <name> with BEFORE,AFTER,INSTEAD OF */ /* complete CREATE TRIGGER <name> with BEFORE,AFTER,INSTEAD OF */
else if (TailMatches3("CREATE", "TRIGGER", MatchAny)) else if (TailMatches3("CREATE", "TRIGGER", MatchAny))
COMPLETE_WITH_LIST3("BEFORE", "AFTER", "INSTEAD OF"); COMPLETE_WITH_LIST3("BEFORE", "AFTER", "INSTEAD OF");
...@@ -2058,17 +2053,17 @@ psql_completion(const char *text, int start, int end) ...@@ -2058,17 +2053,17 @@ psql_completion(const char *text, int start, int end)
* complete CREATE TRIGGER <name> BEFORE,AFTER event ON with a list of * complete CREATE TRIGGER <name> BEFORE,AFTER event ON with a list of
* tables * tables
*/ */
else if (TailMatches5("TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON")) else if (TailMatches6("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* complete CREATE TRIGGER ... INSTEAD OF event ON with a list of views */ /* complete CREATE TRIGGER ... INSTEAD OF event ON with a list of views */
else if (TailMatches4("INSTEAD", "OF", MatchAny, "ON")) else if (TailMatches7("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny, "ON"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
/* complete CREATE TRIGGER ... EXECUTE with PROCEDURE */ /* complete CREATE TRIGGER ... EXECUTE with PROCEDURE */
else if (HeadMatches2("CREATE", "TRIGGER") && TailMatches1("EXECUTE")) else if (HeadMatches2("CREATE", "TRIGGER") && TailMatches1("EXECUTE"))
COMPLETE_WITH_CONST("PROCEDURE"); COMPLETE_WITH_CONST("PROCEDURE");
/* CREATE ROLE,USER,GROUP <name> */ /* CREATE ROLE,USER,GROUP <name> */
else if (TailMatches3("CREATE", "ROLE|GROUP|USER", MatchAny) && else if (Matches3("CREATE", "ROLE|GROUP|USER", MatchAny) &&
!TailMatches2("USER", "MAPPING")) !TailMatches2("USER", "MAPPING"))
{ {
static const char *const list_CREATEROLE[] = static const char *const list_CREATEROLE[] =
...@@ -2083,7 +2078,7 @@ psql_completion(const char *text, int start, int end) ...@@ -2083,7 +2078,7 @@ psql_completion(const char *text, int start, int end)
} }
/* CREATE ROLE,USER,GROUP <name> WITH */ /* CREATE ROLE,USER,GROUP <name> WITH */
else if (TailMatches4("CREATE", "ROLE|GROUP|USER", MatchAny, "WITH")) else if (Matches4("CREATE", "ROLE|GROUP|USER", MatchAny, "WITH"))
{ {
/* Similar to the above, but don't complete "WITH" again. */ /* Similar to the above, but don't complete "WITH" again. */
static const char *const list_CREATEROLE_WITH[] = static const char *const list_CREATEROLE_WITH[] =
...@@ -2101,13 +2096,13 @@ psql_completion(const char *text, int start, int end) ...@@ -2101,13 +2096,13 @@ psql_completion(const char *text, int start, int end)
* complete CREATE ROLE,USER,GROUP <name> ENCRYPTED,UNENCRYPTED with * complete CREATE ROLE,USER,GROUP <name> ENCRYPTED,UNENCRYPTED with
* PASSWORD * PASSWORD
*/ */
else if (TailMatches4("CREATE", "ROLE|USER|GROUP", MatchAny, "ENCRYPTED|UNENCRYPTED")) else if (Matches4("CREATE", "ROLE|USER|GROUP", MatchAny, "ENCRYPTED|UNENCRYPTED"))
COMPLETE_WITH_CONST("PASSWORD"); COMPLETE_WITH_CONST("PASSWORD");
/* complete CREATE ROLE,USER,GROUP <name> IN with ROLE,GROUP */ /* complete CREATE ROLE,USER,GROUP <name> IN with ROLE,GROUP */
else if (TailMatches4("CREATE", "ROLE|USER|GROUP", MatchAny, "IN")) else if (Matches4("CREATE", "ROLE|USER|GROUP", MatchAny, "IN"))
COMPLETE_WITH_LIST2("GROUP", "ROLE"); COMPLETE_WITH_LIST2("GROUP", "ROLE");
/* CREATE VIEW */ /* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* Complete CREATE VIEW <name> with AS */ /* Complete CREATE VIEW <name> with AS */
else if (TailMatches3("CREATE", "VIEW", MatchAny)) else if (TailMatches3("CREATE", "VIEW", MatchAny))
COMPLETE_WITH_CONST("AS"); COMPLETE_WITH_CONST("AS");
...@@ -2116,37 +2111,34 @@ psql_completion(const char *text, int start, int end) ...@@ -2116,37 +2111,34 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("SELECT"); COMPLETE_WITH_CONST("SELECT");
/* CREATE MATERIALIZED VIEW */ /* CREATE MATERIALIZED VIEW */
else if (TailMatches2("CREATE", "MATERIALIZED")) else if (Matches2("CREATE", "MATERIALIZED"))
COMPLETE_WITH_CONST("VIEW"); COMPLETE_WITH_CONST("VIEW");
/* Complete CREATE MATERIALIZED VIEW <name> with AS */ /* Complete CREATE MATERIALIZED VIEW <name> with AS */
else if (TailMatches4("CREATE", "MATERIALIZED", "VIEW", MatchAny)) else if (Matches4("CREATE", "MATERIALIZED", "VIEW", MatchAny))
COMPLETE_WITH_CONST("AS"); COMPLETE_WITH_CONST("AS");
/* Complete "CREATE MATERIALIZED VIEW <sth> AS with "SELECT" */ /* Complete "CREATE MATERIALIZED VIEW <sth> AS with "SELECT" */
else if (TailMatches5("CREATE", "MATERIALIZED", "VIEW", MatchAny, "AS")) else if (Matches5("CREATE", "MATERIALIZED", "VIEW", MatchAny, "AS"))
COMPLETE_WITH_CONST("SELECT"); COMPLETE_WITH_CONST("SELECT");
/* CREATE EVENT TRIGGER */ /* CREATE EVENT TRIGGER */
else if (TailMatches2("CREATE", "EVENT")) else if (Matches2("CREATE", "EVENT"))
COMPLETE_WITH_CONST("TRIGGER"); COMPLETE_WITH_CONST("TRIGGER");
/* Complete CREATE EVENT TRIGGER <name> with ON */ /* Complete CREATE EVENT TRIGGER <name> with ON */
else if (TailMatches4("CREATE", "EVENT", "TRIGGER", MatchAny)) else if (Matches4("CREATE", "EVENT", "TRIGGER", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* Complete CREATE EVENT TRIGGER <name> ON with event_type */ /* Complete CREATE EVENT TRIGGER <name> ON with event_type */
else if (TailMatches5("CREATE", "EVENT", "TRIGGER", MatchAny, "ON")) else if (Matches5("CREATE", "EVENT", "TRIGGER", MatchAny, "ON"))
COMPLETE_WITH_LIST3("ddl_command_start", "ddl_command_end", "sql_drop"); COMPLETE_WITH_LIST3("ddl_command_start", "ddl_command_end", "sql_drop");
/* DECLARE */ /* DECLARE */
else if (TailMatches2("DECLARE", MatchAny)) else if (Matches2("DECLARE", MatchAny))
COMPLETE_WITH_LIST5("BINARY", "INSENSITIVE", "SCROLL", "NO SCROLL", COMPLETE_WITH_LIST5("BINARY", "INSENSITIVE", "SCROLL", "NO SCROLL",
"CURSOR"); "CURSOR");
else if (HeadMatches1("DECLARE") && TailMatches1("CURSOR"))
/* CURSOR */
else if (TailMatches1("CURSOR"))
COMPLETE_WITH_LIST3("WITH HOLD", "WITHOUT HOLD", "FOR"); COMPLETE_WITH_LIST3("WITH HOLD", "WITHOUT HOLD", "FOR");
/* DELETE */ /* DELETE --- can be inside EXPLAIN, RULE, etc */
/* ... despite which, only complete DELETE with FROM at start of line */
/* Complete DELETE with FROM, only at start of line */
else if (Matches1("DELETE")) else if (Matches1("DELETE"))
COMPLETE_WITH_CONST("FROM"); COMPLETE_WITH_CONST("FROM");
/* Complete DELETE FROM with a list of tables */ /* Complete DELETE FROM with a list of tables */
...@@ -2158,92 +2150,88 @@ psql_completion(const char *text, int start, int end) ...@@ -2158,92 +2150,88 @@ psql_completion(const char *text, int start, int end)
/* XXX: implement tab completion for DELETE ... USING */ /* XXX: implement tab completion for DELETE ... USING */
/* DISCARD */ /* DISCARD */
else if (TailMatches1("DISCARD")) else if (Matches1("DISCARD"))
COMPLETE_WITH_LIST4("ALL", "PLANS", "SEQUENCES", "TEMP"); COMPLETE_WITH_LIST4("ALL", "PLANS", "SEQUENCES", "TEMP");
/* DO */ /* DO */
else if (Matches1("DO"))
/*
* Complete DO with LANGUAGE.
*/
else if (TailMatches1("DO"))
COMPLETE_WITH_CONST("LANGUAGE"); COMPLETE_WITH_CONST("LANGUAGE");
/* DROP (when not the previous word) */ /* DROP */
/* DROP object with CASCADE / RESTRICT */ /* Complete DROP object with CASCADE / RESTRICT */
else if (TailMatches3("DROP", else if (Matches3("DROP",
"COLLATION|CONVERSION|DOMAIN|EXTENSION|INDEX|LANGUAGE|SCHEMA|SEQUENCE|SERVER|TABLE|TYPE|VIEW", "COLLATION|CONVERSION|DOMAIN|EXTENSION|INDEX|LANGUAGE|SCHEMA|SEQUENCE|SERVER|TABLE|TYPE|VIEW",
MatchAny) || MatchAny) ||
(TailMatches4("DROP", "AGGREGATE|FUNCTION", MatchAny, MatchAny) && (Matches4("DROP", "AGGREGATE|FUNCTION", MatchAny, MatchAny) &&
ends_with(prev_wd, ')')) || ends_with(prev_wd, ')')) ||
TailMatches4("DROP", "EVENT", "TRIGGER", MatchAny) || Matches4("DROP", "EVENT", "TRIGGER", MatchAny) ||
TailMatches5("DROP", "FOREIGN", "DATA", "WRAPPER", MatchAny) || Matches5("DROP", "FOREIGN", "DATA", "WRAPPER", MatchAny) ||
TailMatches4("DROP", "FOREIGN", "TABLE", MatchAny) || Matches4("DROP", "FOREIGN", "TABLE", MatchAny) ||
TailMatches5("DROP", "TEXT", "SEARCH", "CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny)) Matches5("DROP", "TEXT", "SEARCH", "CONFIGURATION|DICTIONARY|PARSER|TEMPLATE", MatchAny))
COMPLETE_WITH_LIST2("CASCADE", "RESTRICT"); COMPLETE_WITH_LIST2("CASCADE", "RESTRICT");
/* help completing some of the variants */ /* help completing some of the variants */
else if (TailMatches3("DROP", "AGGREGATE|FUNCTION", MatchAny)) else if (Matches3("DROP", "AGGREGATE|FUNCTION", MatchAny))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
else if (TailMatches4("DROP", "AGGREGATE|FUNCTION", MatchAny, "(")) else if (Matches4("DROP", "AGGREGATE|FUNCTION", MatchAny, "("))
COMPLETE_WITH_FUNCTION_ARG(prev2_wd); COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
else if (TailMatches2("DROP", "FOREIGN")) else if (Matches2("DROP", "FOREIGN"))
COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE"); COMPLETE_WITH_LIST2("DATA WRAPPER", "TABLE");
/* DROP MATERIALIZED VIEW */ /* DROP MATERIALIZED VIEW */
else if (TailMatches2("DROP", "MATERIALIZED")) else if (Matches2("DROP", "MATERIALIZED"))
COMPLETE_WITH_CONST("VIEW"); COMPLETE_WITH_CONST("VIEW");
else if (TailMatches3("DROP", "MATERIALIZED", "VIEW")) else if (Matches3("DROP", "MATERIALIZED", "VIEW"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
/* DROP OWNED BY */ /* DROP OWNED BY */
else if (TailMatches2("DROP", "OWNED")) else if (Matches2("DROP", "OWNED"))
COMPLETE_WITH_CONST("BY"); COMPLETE_WITH_CONST("BY");
else if (TailMatches3("DROP", "OWNED", "BY")) else if (Matches3("DROP", "OWNED", "BY"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
else if (TailMatches3("DROP", "TEXT", "SEARCH")) else if (Matches3("DROP", "TEXT", "SEARCH"))
COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE"); COMPLETE_WITH_LIST4("CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE");
/* DROP TRIGGER */ /* DROP TRIGGER */
else if (TailMatches3("DROP", "TRIGGER", MatchAny)) else if (Matches3("DROP", "TRIGGER", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches4("DROP", "TRIGGER", MatchAny, "ON")) else if (Matches4("DROP", "TRIGGER", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
} }
else if (TailMatches5("DROP", "TRIGGER", MatchAny, "ON", MatchAny)) else if (Matches5("DROP", "TRIGGER", MatchAny, "ON", MatchAny))
COMPLETE_WITH_LIST2("CASCADE", "RESTRICT"); COMPLETE_WITH_LIST2("CASCADE", "RESTRICT");
/* DROP EVENT TRIGGER */ /* DROP EVENT TRIGGER */
else if (TailMatches2("DROP", "EVENT")) else if (Matches2("DROP", "EVENT"))
COMPLETE_WITH_CONST("TRIGGER"); COMPLETE_WITH_CONST("TRIGGER");
else if (TailMatches3("DROP", "EVENT", "TRIGGER")) else if (Matches3("DROP", "EVENT", "TRIGGER"))
COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers); COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
/* DROP POLICY <name> */ /* DROP POLICY <name> */
else if (TailMatches2("DROP", "POLICY")) else if (Matches2("DROP", "POLICY"))
COMPLETE_WITH_QUERY(Query_for_list_of_policies); COMPLETE_WITH_QUERY(Query_for_list_of_policies);
/* DROP POLICY <name> ON */ /* DROP POLICY <name> ON */
else if (TailMatches3("DROP", "POLICY", MatchAny)) else if (Matches3("DROP", "POLICY", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
/* DROP POLICY <name> ON <table> */ /* DROP POLICY <name> ON <table> */
else if (TailMatches4("DROP", "POLICY", MatchAny, "ON")) else if (Matches4("DROP", "POLICY", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy);
} }
/* DROP RULE */ /* DROP RULE */
else if (TailMatches3("DROP", "RULE", MatchAny)) else if (Matches3("DROP", "RULE", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches4("DROP", "RULE", MatchAny, "ON")) else if (Matches4("DROP", "RULE", MatchAny, "ON"))
{ {
completion_info_charp = prev2_wd; completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule); COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule);
} }
else if (TailMatches5("DROP", "RULE", MatchAny, "ON", MatchAny)) else if (Matches5("DROP", "RULE", MatchAny, "ON", MatchAny))
COMPLETE_WITH_LIST2("CASCADE", "RESTRICT"); COMPLETE_WITH_LIST2("CASCADE", "RESTRICT");
/* EXECUTE */ /* EXECUTE */
...@@ -2255,22 +2243,22 @@ psql_completion(const char *text, int start, int end) ...@@ -2255,22 +2243,22 @@ psql_completion(const char *text, int start, int end)
/* /*
* Complete EXPLAIN [ANALYZE] [VERBOSE] with list of EXPLAIN-able commands * Complete EXPLAIN [ANALYZE] [VERBOSE] with list of EXPLAIN-able commands
*/ */
else if (TailMatches1("EXPLAIN")) else if (Matches1("EXPLAIN"))
COMPLETE_WITH_LIST7("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE", COMPLETE_WITH_LIST7("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE",
"ANALYZE", "VERBOSE"); "ANALYZE", "VERBOSE");
else if (TailMatches2("EXPLAIN", "ANALYZE")) else if (Matches2("EXPLAIN", "ANALYZE"))
COMPLETE_WITH_LIST6("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE", COMPLETE_WITH_LIST6("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE",
"VERBOSE"); "VERBOSE");
else if (TailMatches2("EXPLAIN", "VERBOSE") || else if (Matches2("EXPLAIN", "VERBOSE") ||
TailMatches3("EXPLAIN", "ANALYZE", "VERBOSE")) Matches3("EXPLAIN", "ANALYZE", "VERBOSE"))
COMPLETE_WITH_LIST5("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE"); COMPLETE_WITH_LIST5("SELECT", "INSERT", "DELETE", "UPDATE", "DECLARE");
/* FETCH && MOVE */ /* FETCH && MOVE */
/* Complete FETCH with one of FORWARD, BACKWARD, RELATIVE */ /* Complete FETCH with one of FORWARD, BACKWARD, RELATIVE */
else if (TailMatches1("FETCH|MOVE")) else if (Matches1("FETCH|MOVE"))
COMPLETE_WITH_LIST4("ABSOLUTE", "BACKWARD", "FORWARD", "RELATIVE"); COMPLETE_WITH_LIST4("ABSOLUTE", "BACKWARD", "FORWARD", "RELATIVE");
/* Complete FETCH <sth> with one of ALL, NEXT, PRIOR */ /* Complete FETCH <sth> with one of ALL, NEXT, PRIOR */
else if (TailMatches2("FETCH|MOVE", MatchAny)) else if (Matches2("FETCH|MOVE", MatchAny))
COMPLETE_WITH_LIST3("ALL", "NEXT", "PRIOR"); COMPLETE_WITH_LIST3("ALL", "NEXT", "PRIOR");
/* /*
...@@ -2278,7 +2266,7 @@ psql_completion(const char *text, int start, int end) ...@@ -2278,7 +2266,7 @@ psql_completion(const char *text, int start, int end)
* but we may as well tab-complete both: perhaps some users prefer one * but we may as well tab-complete both: perhaps some users prefer one
* variant or the other. * variant or the other.
*/ */
else if (TailMatches3("FETCH|MOVE", MatchAny, MatchAny)) else if (Matches3("FETCH|MOVE", MatchAny, MatchAny))
COMPLETE_WITH_LIST2("FROM", "IN"); COMPLETE_WITH_LIST2("FROM", "IN");
/* FOREIGN DATA WRAPPER */ /* FOREIGN DATA WRAPPER */
...@@ -2296,7 +2284,7 @@ psql_completion(const char *text, int start, int end) ...@@ -2296,7 +2284,7 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches2("FOREIGN", "SERVER")) else if (TailMatches2("FOREIGN", "SERVER"))
COMPLETE_WITH_QUERY(Query_for_list_of_servers); COMPLETE_WITH_QUERY(Query_for_list_of_servers);
/* GRANT && REVOKE */ /* GRANT && REVOKE --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* Complete GRANT/REVOKE with a list of roles and privileges */ /* Complete GRANT/REVOKE with a list of roles and privileges */
else if (TailMatches1("GRANT|REVOKE")) else if (TailMatches1("GRANT|REVOKE"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles COMPLETE_WITH_QUERY(Query_for_list_of_roles
...@@ -2442,12 +2430,12 @@ psql_completion(const char *text, int start, int end) ...@@ -2442,12 +2430,12 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("BY"); COMPLETE_WITH_CONST("BY");
/* IMPORT FOREIGN SCHEMA */ /* IMPORT FOREIGN SCHEMA */
else if (TailMatches1("IMPORT")) else if (Matches1("IMPORT"))
COMPLETE_WITH_CONST("FOREIGN SCHEMA"); COMPLETE_WITH_CONST("FOREIGN SCHEMA");
else if (TailMatches2("IMPORT", "FOREIGN")) else if (Matches2("IMPORT", "FOREIGN"))
COMPLETE_WITH_CONST("SCHEMA"); COMPLETE_WITH_CONST("SCHEMA");
/* INSERT */ /* INSERT --- can be inside EXPLAIN, RULE, etc */
/* Complete INSERT with "INTO" */ /* Complete INSERT with "INTO" */
else if (TailMatches1("INSERT")) else if (TailMatches1("INSERT"))
COMPLETE_WITH_CONST("INTO"); COMPLETE_WITH_CONST("INTO");
...@@ -2479,29 +2467,29 @@ psql_completion(const char *text, int start, int end) ...@@ -2479,29 +2467,29 @@ psql_completion(const char *text, int start, int end)
/* LOCK */ /* LOCK */
/* Complete LOCK [TABLE] with a list of tables */ /* Complete LOCK [TABLE] with a list of tables */
else if (TailMatches1("LOCK")) else if (Matches1("LOCK"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
" UNION SELECT 'TABLE'"); " UNION SELECT 'TABLE'");
else if (TailMatches2("LOCK", "TABLE")) else if (Matches2("LOCK", "TABLE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, ""); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, "");
/* For the following, handle the case of a single table only for now */ /* For the following, handle the case of a single table only for now */
/* Complete LOCK [TABLE] <table> with "IN" */ /* Complete LOCK [TABLE] <table> with "IN" */
else if (TailMatches2("LOCK", MatchAnyExcept("TABLE")) || else if (Matches2("LOCK", MatchAnyExcept("TABLE")) ||
TailMatches3("LOCK", "TABLE", MatchAny)) Matches3("LOCK", "TABLE", MatchAny))
COMPLETE_WITH_CONST("IN"); COMPLETE_WITH_CONST("IN");
/* Complete LOCK [TABLE] <table> IN with a lock mode */ /* Complete LOCK [TABLE] <table> IN with a lock mode */
else if (TailMatches3("LOCK", MatchAny, "IN") || else if (Matches3("LOCK", MatchAny, "IN") ||
TailMatches4("LOCK", "TABLE", MatchAny, "IN")) Matches4("LOCK", "TABLE", MatchAny, "IN"))
COMPLETE_WITH_LIST8("ACCESS SHARE MODE", COMPLETE_WITH_LIST8("ACCESS SHARE MODE",
"ROW SHARE MODE", "ROW EXCLUSIVE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE",
"SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE",
"SHARE ROW EXCLUSIVE MODE", "SHARE ROW EXCLUSIVE MODE",
"EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE"); "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE");
/* NOTIFY */ /* NOTIFY --- can be inside EXPLAIN, RULE, etc */
else if (TailMatches1("NOTIFY")) else if (TailMatches1("NOTIFY"))
COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'"); COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'");
...@@ -2520,8 +2508,8 @@ psql_completion(const char *text, int start, int end) ...@@ -2520,8 +2508,8 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_ATTR(prev3_wd, ""); COMPLETE_WITH_ATTR(prev3_wd, "");
/* PREPARE xx AS */ /* PREPARE xx AS */
else if (TailMatches3("PREPARE", MatchAny, "AS")) else if (Matches3("PREPARE", MatchAny, "AS"))
COMPLETE_WITH_LIST4("SELECT", "UPDATE", "INSERT", "DELETE"); COMPLETE_WITH_LIST4("SELECT", "UPDATE", "INSERT", "DELETE FROM");
/* /*
* PREPARE TRANSACTION is missing on purpose. It's intended for transaction * PREPARE TRANSACTION is missing on purpose. It's intended for transaction
...@@ -2529,72 +2517,69 @@ psql_completion(const char *text, int start, int end) ...@@ -2529,72 +2517,69 @@ psql_completion(const char *text, int start, int end)
*/ */
/* REASSIGN OWNED BY xxx TO yyy */ /* REASSIGN OWNED BY xxx TO yyy */
else if (TailMatches1("REASSIGN")) else if (Matches1("REASSIGN"))
COMPLETE_WITH_CONST("OWNED BY"); COMPLETE_WITH_CONST("OWNED BY");
else if (TailMatches2("REASSIGN", "OWNED")) else if (Matches2("REASSIGN", "OWNED"))
COMPLETE_WITH_CONST("BY"); COMPLETE_WITH_CONST("BY");
else if (TailMatches3("REASSIGN", "OWNED", "BY")) else if (Matches3("REASSIGN", "OWNED", "BY"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
else if (TailMatches4("REASSIGN", "OWNED", "BY", MatchAny)) else if (Matches4("REASSIGN", "OWNED", "BY", MatchAny))
COMPLETE_WITH_CONST("TO"); COMPLETE_WITH_CONST("TO");
else if (TailMatches5("REASSIGN", "OWNED", "BY", MatchAny, "TO")) else if (Matches5("REASSIGN", "OWNED", "BY", MatchAny, "TO"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
/* REFRESH MATERIALIZED VIEW */ /* REFRESH MATERIALIZED VIEW */
else if (TailMatches1("REFRESH")) else if (Matches1("REFRESH"))
COMPLETE_WITH_CONST("MATERIALIZED VIEW"); COMPLETE_WITH_CONST("MATERIALIZED VIEW");
else if (TailMatches2("REFRESH", "MATERIALIZED")) else if (Matches2("REFRESH", "MATERIALIZED"))
COMPLETE_WITH_CONST("VIEW"); COMPLETE_WITH_CONST("VIEW");
else if (TailMatches3("REFRESH", "MATERIALIZED", "VIEW")) else if (Matches3("REFRESH", "MATERIALIZED", "VIEW"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews,
" UNION SELECT 'CONCURRENTLY'"); " UNION SELECT 'CONCURRENTLY'");
else if (TailMatches4("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY")) else if (Matches4("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
else if (TailMatches4("REFRESH", "MATERIALIZED", "VIEW", MatchAny)) else if (Matches4("REFRESH", "MATERIALIZED", "VIEW", MatchAny))
COMPLETE_WITH_CONST("WITH"); COMPLETE_WITH_CONST("WITH");
else if (TailMatches5("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny)) else if (Matches5("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny))
COMPLETE_WITH_CONST("WITH DATA"); COMPLETE_WITH_CONST("WITH DATA");
else if (TailMatches5("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH")) else if (Matches5("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH"))
COMPLETE_WITH_LIST2("NO DATA", "DATA"); COMPLETE_WITH_LIST2("NO DATA", "DATA");
else if (TailMatches6("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny, "WITH")) else if (Matches6("REFRESH", "MATERIALIZED", "VIEW", "CONCURRENTLY", MatchAny, "WITH"))
COMPLETE_WITH_CONST("DATA"); COMPLETE_WITH_CONST("DATA");
else if (TailMatches6("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH", "NO")) else if (Matches6("REFRESH", "MATERIALIZED", "VIEW", MatchAny, "WITH", "NO"))
COMPLETE_WITH_CONST("DATA"); COMPLETE_WITH_CONST("DATA");
/* REINDEX */ /* REINDEX */
else if (TailMatches1("REINDEX")) else if (Matches1("REINDEX"))
COMPLETE_WITH_LIST5("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE"); COMPLETE_WITH_LIST5("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE");
else if (TailMatches2("REINDEX", MatchAny)) else if (Matches2("REINDEX", "TABLE"))
{ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL);
if (TailMatches1("TABLE")) else if (Matches2("REINDEX", "INDEX"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
else if (TailMatches1("INDEX")) else if (Matches2("REINDEX", "SCHEMA"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL); COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
else if (TailMatches1("SCHEMA")) else if (Matches2("REINDEX", "SYSTEM|DATABASE"))
COMPLETE_WITH_QUERY(Query_for_list_of_schemas); COMPLETE_WITH_QUERY(Query_for_list_of_databases);
else if (TailMatches1("SYSTEM|DATABASE"))
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
}
/* SECURITY LABEL */ /* SECURITY LABEL */
else if (TailMatches1("SECURITY")) else if (Matches1("SECURITY"))
COMPLETE_WITH_CONST("LABEL"); COMPLETE_WITH_CONST("LABEL");
else if (TailMatches2("SECURITY", "LABEL")) else if (Matches2("SECURITY", "LABEL"))
COMPLETE_WITH_LIST2("ON", "FOR"); COMPLETE_WITH_LIST2("ON", "FOR");
else if (TailMatches4("SECURITY", "LABEL", "FOR", MatchAny)) else if (Matches4("SECURITY", "LABEL", "FOR", MatchAny))
COMPLETE_WITH_CONST("ON"); COMPLETE_WITH_CONST("ON");
else if (TailMatches3("SECURITY", "LABEL", "ON") || else if (Matches3("SECURITY", "LABEL", "ON") ||
TailMatches5("SECURITY", "LABEL", "FOR", MatchAny, "ON")) Matches5("SECURITY", "LABEL", "FOR", MatchAny, "ON"))
{ {
static const char *const list_SECURITY_LABEL[] = static const char *const list_SECURITY_LABEL[] =
{"TABLE", "COLUMN", "AGGREGATE", "DATABASE", "DOMAIN", {"TABLE", "COLUMN", "AGGREGATE", "DATABASE", "DOMAIN",
"EVENT TRIGGER", "FOREIGN TABLE", "FUNCTION", "LARGE OBJECT", "EVENT TRIGGER", "FOREIGN TABLE", "FUNCTION", "LARGE OBJECT",
"MATERIALIZED VIEW", "LANGUAGE", "ROLE", "SCHEMA", "MATERIALIZED VIEW", "LANGUAGE", "ROLE", "SCHEMA",
"SEQUENCE", "TABLESPACE", "TYPE", "VIEW", NULL}; "SEQUENCE", "TABLESPACE", "TYPE", "VIEW", NULL};
COMPLETE_WITH_LIST(list_SECURITY_LABEL); COMPLETE_WITH_LIST(list_SECURITY_LABEL);
} }
else if (TailMatches5("SECURITY", "LABEL", "ON", MatchAny, MatchAny)) else if (Matches5("SECURITY", "LABEL", "ON", MatchAny, MatchAny))
COMPLETE_WITH_CONST("IS"); COMPLETE_WITH_CONST("IS");
/* SELECT */ /* SELECT */
...@@ -2602,43 +2587,43 @@ psql_completion(const char *text, int start, int end) ...@@ -2602,43 +2587,43 @@ psql_completion(const char *text, int start, int end)
/* SET, RESET, SHOW */ /* SET, RESET, SHOW */
/* Complete with a variable name */ /* Complete with a variable name */
else if (TailMatches1("SET|RESET") && !Matches3("UPDATE", MatchAny, "SET")) else if (Matches1("SET|RESET"))
COMPLETE_WITH_QUERY(Query_for_list_of_set_vars); COMPLETE_WITH_QUERY(Query_for_list_of_set_vars);
else if (TailMatches1("SHOW")) else if (Matches1("SHOW"))
COMPLETE_WITH_QUERY(Query_for_list_of_show_vars); COMPLETE_WITH_QUERY(Query_for_list_of_show_vars);
/* Complete "SET TRANSACTION" */ /* Complete "SET TRANSACTION" */
else if (TailMatches2("SET|BEGIN|START", "TRANSACTION") || else if (Matches2("SET|BEGIN|START", "TRANSACTION") ||
TailMatches2("BEGIN", "WORK") || Matches2("BEGIN", "WORK") ||
TailMatches4("SESSION", "CHARACTERISTICS", "AS", "TRANSACTION")) Matches5("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION"))
COMPLETE_WITH_LIST2("ISOLATION LEVEL", "READ"); COMPLETE_WITH_LIST2("ISOLATION LEVEL", "READ");
else if (TailMatches3("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION") || else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION") ||
TailMatches4("CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION")) Matches6("SET", "SESSION", "CHARACTERISTICS", "AS", "TRANSACTION", "ISOLATION"))
COMPLETE_WITH_CONST("LEVEL"); COMPLETE_WITH_CONST("LEVEL");
else if (TailMatches4("SET|BEGIN|START|AS", "TRANSACTION|WORK", "ISOLATION", "LEVEL")) else if (Matches4("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL"))
COMPLETE_WITH_LIST3("READ", "REPEATABLE READ", "SERIALIZABLE"); COMPLETE_WITH_LIST3("READ", "REPEATABLE READ", "SERIALIZABLE");
else if (TailMatches4("TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ")) else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "READ"))
COMPLETE_WITH_LIST2("UNCOMMITTED", "COMMITTED"); COMPLETE_WITH_LIST2("UNCOMMITTED", "COMMITTED");
else if (TailMatches4("TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE")) else if (Matches5("SET|BEGIN|START", "TRANSACTION|WORK", "ISOLATION", "LEVEL", "REPEATABLE"))
COMPLETE_WITH_CONST("READ"); COMPLETE_WITH_CONST("READ");
else if (TailMatches3("SET|BEGIN|START|AS", "TRANSACTION|WORK", "READ")) else if (Matches3("SET|BEGIN|START", "TRANSACTION|WORK", "READ"))
COMPLETE_WITH_LIST2("ONLY", "WRITE"); COMPLETE_WITH_LIST2("ONLY", "WRITE");
/* SET CONSTRAINTS */ /* SET CONSTRAINTS */
else if (TailMatches2("SET", "CONSTRAINTS")) else if (Matches2("SET", "CONSTRAINTS"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_constraints_with_schema, "UNION SELECT 'ALL'"); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_constraints_with_schema, "UNION SELECT 'ALL'");
/* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */ /* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */
else if (TailMatches3("SET", "CONSTRAINTS", MatchAny)) else if (Matches3("SET", "CONSTRAINTS", MatchAny))
COMPLETE_WITH_LIST2("DEFERRED", "IMMEDIATE"); COMPLETE_WITH_LIST2("DEFERRED", "IMMEDIATE");
/* Complete SET ROLE */ /* Complete SET ROLE */
else if (TailMatches2("SET", "ROLE")) else if (Matches2("SET", "ROLE"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles); COMPLETE_WITH_QUERY(Query_for_list_of_roles);
/* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */ /* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */
else if (TailMatches2("SET", "SESSION")) else if (Matches2("SET", "SESSION"))
COMPLETE_WITH_LIST2("AUTHORIZATION", "CHARACTERISTICS AS TRANSACTION"); COMPLETE_WITH_LIST2("AUTHORIZATION", "CHARACTERISTICS AS TRANSACTION");
/* Complete SET SESSION AUTHORIZATION with username */ /* Complete SET SESSION AUTHORIZATION with username */
else if (TailMatches3("SET", "SESSION", "AUTHORIZATION")) else if (Matches3("SET", "SESSION", "AUTHORIZATION"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles " UNION SELECT 'DEFAULT'"); COMPLETE_WITH_QUERY(Query_for_list_of_roles " UNION SELECT 'DEFAULT'");
/* Complete RESET SESSION with AUTHORIZATION */ /* Complete RESET SESSION with AUTHORIZATION */
else if (TailMatches2("RESET", "SESSION")) else if (Matches2("RESET", "SESSION"))
COMPLETE_WITH_CONST("AUTHORIZATION"); COMPLETE_WITH_CONST("AUTHORIZATION");
/* Complete SET <var> with "TO" */ /* Complete SET <var> with "TO" */
else if (Matches2("SET", MatchAny)) else if (Matches2("SET", MatchAny))
...@@ -2696,49 +2681,42 @@ psql_completion(const char *text, int start, int end) ...@@ -2696,49 +2681,42 @@ psql_completion(const char *text, int start, int end)
/* TABLESAMPLE */ /* TABLESAMPLE */
else if (TailMatches1("TABLESAMPLE")) else if (TailMatches1("TABLESAMPLE"))
COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods); COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods);
else if (TailMatches2("TABLESAMPLE", MatchAny)) else if (TailMatches2("TABLESAMPLE", MatchAny))
COMPLETE_WITH_CONST("("); COMPLETE_WITH_CONST("(");
/* TRUNCATE */ /* TRUNCATE */
else if (TailMatches1("TRUNCATE")) else if (Matches1("TRUNCATE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
/* UNLISTEN */ /* UNLISTEN */
else if (TailMatches1("UNLISTEN")) else if (Matches1("UNLISTEN"))
COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s' UNION SELECT '*'"); COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s' UNION SELECT '*'");
/* UPDATE */ /* UPDATE --- can be inside EXPLAIN, RULE, etc */
/* If prev. word is UPDATE suggest a list of tables */ /* If prev. word is UPDATE suggest a list of tables */
else if (TailMatches1("UPDATE")) else if (TailMatches1("UPDATE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_updatables, NULL);
/* Complete UPDATE <table> with "SET" */ /* Complete UPDATE <table> with "SET" */
else if (TailMatches2("UPDATE", MatchAny)) else if (TailMatches2("UPDATE", MatchAny))
COMPLETE_WITH_CONST("SET"); COMPLETE_WITH_CONST("SET");
/* Complete UPDATE <table> SET with list of attributes */
/* else if (TailMatches3("UPDATE", MatchAny, "SET"))
* If the previous word is SET (and it wasn't caught above as the _first_
* word) the word before it was (hopefully) a table name and we'll now
* make a list of attributes.
*/
else if (TailMatches2(MatchAny, "SET"))
COMPLETE_WITH_ATTR(prev2_wd, ""); COMPLETE_WITH_ATTR(prev2_wd, "");
/* UPDATE <table> SET <attr> = */
/* UPDATE xx SET yy = */
else if (TailMatches4("UPDATE", MatchAny, "SET", MatchAny)) else if (TailMatches4("UPDATE", MatchAny, "SET", MatchAny))
COMPLETE_WITH_CONST("="); COMPLETE_WITH_CONST("=");
/* USER MAPPING */ /* USER MAPPING */
else if (TailMatches3("ALTER|CREATE|DROP", "USER", "MAPPING")) else if (Matches3("ALTER|CREATE|DROP", "USER", "MAPPING"))
COMPLETE_WITH_CONST("FOR"); COMPLETE_WITH_CONST("FOR");
else if (TailMatches4("CREATE", "USER", "MAPPING", "FOR")) else if (Matches4("CREATE", "USER", "MAPPING", "FOR"))
COMPLETE_WITH_QUERY(Query_for_list_of_roles COMPLETE_WITH_QUERY(Query_for_list_of_roles
" UNION SELECT 'CURRENT_USER'" " UNION SELECT 'CURRENT_USER'"
" UNION SELECT 'PUBLIC'" " UNION SELECT 'PUBLIC'"
" UNION SELECT 'USER'"); " UNION SELECT 'USER'");
else if (TailMatches4("ALTER|DROP", "USER", "MAPPING", "FOR")) else if (Matches4("ALTER|DROP", "USER", "MAPPING", "FOR"))
COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings); COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
else if (TailMatches5("CREATE|ALTER|DROP", "USER", "MAPPING", "FOR", MatchAny)) else if (Matches5("CREATE|ALTER|DROP", "USER", "MAPPING", "FOR", MatchAny))
COMPLETE_WITH_CONST("SERVER"); COMPLETE_WITH_CONST("SERVER");
/* /*
...@@ -2780,8 +2758,8 @@ psql_completion(const char *text, int start, int end) ...@@ -2780,8 +2758,8 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_CONST("RECURSIVE"); COMPLETE_WITH_CONST("RECURSIVE");
/* ANALYZE */ /* ANALYZE */
/* If the previous word is ANALYZE, produce list of tables */ /* Complete with list of tables */
else if (TailMatches1("ANALYZE")) else if (Matches1("ANALYZE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL); COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL);
/* WHERE */ /* WHERE */
......
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