Commit bf0aa7c4 authored by Michael Paquier's avatar Michael Paquier

Add tab completion for CREATE [OR REPLACE] TRIGGER in psql

92bf7e2d has added support for this grammar.

Author: Noriyoshi Shinoda
Discussion: https://postgr.es/m/TU4PR8401MB115244623CF4724DCA0D507FEEE30@TU4PR8401MB1152.NAMPRD84.PROD.OUTLOOK.COM
parent cf2acaf4
...@@ -1580,7 +1580,7 @@ psql_completion(const char *text, int start, int end) ...@@ -1580,7 +1580,7 @@ psql_completion(const char *text, int start, int end)
/* complete with something you can create or replace */ /* complete with something you can create or replace */
else if (TailMatches("CREATE", "OR", "REPLACE")) else if (TailMatches("CREATE", "OR", "REPLACE"))
COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW", COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW",
"AGGREGATE", "TRANSFORM"); "AGGREGATE", "TRANSFORM", "TRIGGER");
/* DROP, but not DROP embedded in other commands */ /* DROP, but not DROP embedded in other commands */
/* complete with something you can drop */ /* complete with something you can drop */
...@@ -2712,31 +2712,56 @@ psql_completion(const char *text, int start, int end) ...@@ -2712,31 +2712,56 @@ psql_completion(const char *text, int start, int end)
"slot_name", "synchronous_commit"); "slot_name", "synchronous_commit");
/* CREATE TRIGGER --- is allowed inside CREATE SCHEMA, so use TailMatches */ /* CREATE TRIGGER --- is allowed inside CREATE SCHEMA, so use TailMatches */
/* complete CREATE TRIGGER <name> with BEFORE,AFTER,INSTEAD OF */
else if (TailMatches("CREATE", "TRIGGER", MatchAny)) /*
* Complete CREATE [ OR REPLACE ] TRIGGER <name> with BEFORE|AFTER|INSTEAD
* OF.
*/
else if (TailMatches("CREATE", "TRIGGER", MatchAny) ||
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny))
COMPLETE_WITH("BEFORE", "AFTER", "INSTEAD OF"); COMPLETE_WITH("BEFORE", "AFTER", "INSTEAD OF");
/* complete CREATE TRIGGER <name> BEFORE,AFTER with an event */
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER")) /*
* Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER with an
* event.
*/
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER") ||
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "BEFORE|AFTER"))
COMPLETE_WITH("INSERT", "DELETE", "UPDATE", "TRUNCATE"); COMPLETE_WITH("INSERT", "DELETE", "UPDATE", "TRUNCATE");
/* complete CREATE TRIGGER <name> INSTEAD OF with an event */ /* Complete CREATE [ OR REPLACE ] TRIGGER <name> INSTEAD OF with an event */
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF")) else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF") ||
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "INSTEAD", "OF"))
COMPLETE_WITH("INSERT", "DELETE", "UPDATE"); COMPLETE_WITH("INSERT", "DELETE", "UPDATE");
/* complete CREATE TRIGGER <name> BEFORE,AFTER sth with OR,ON */
/*
* Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER sth with
* OR|ON.
*/
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny) || else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny) ||
TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny)) TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny) ||
TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny) ||
TailMatches("CREATE", "OR", "REPLACE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny))
COMPLETE_WITH("ON", "OR"); COMPLETE_WITH("ON", "OR");
/* /*
* complete CREATE TRIGGER <name> BEFORE,AFTER event ON with a list of * Complete CREATE [ OR REPLACE ] TRIGGER <name> BEFORE,AFTER event ON
* tables. EXECUTE FUNCTION is the recommended grammar instead of EXECUTE * with a list of tables. EXECUTE FUNCTION is the recommended grammar
* PROCEDURE in version 11 and upwards. * instead of EXECUTE PROCEDURE in version 11 and upwards.
*/ */
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON")) else if (TailMatches("CREATE", "TRIGGER", MatchAny, "BEFORE|AFTER", MatchAny, "ON") ||
TailMatches("CREATE", "OR", "REPLACE", "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 */
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny, "ON")) /*
* Complete CREATE [ OR REPLACE ] TRIGGER ... INSTEAD OF event ON with a
* list of views.
*/
else if (TailMatches("CREATE", "TRIGGER", MatchAny, "INSTEAD", "OF", MatchAny, "ON") ||
TailMatches("CREATE", "OR", "REPLACE", "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);
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("ON", MatchAny)) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("ON", MatchAny))
{ {
if (pset.sversion >= 110000) if (pset.sversion >= 110000)
COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY", COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY",
...@@ -2745,7 +2770,8 @@ psql_completion(const char *text, int start, int end) ...@@ -2745,7 +2770,8 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY", COMPLETE_WITH("NOT DEFERRABLE", "DEFERRABLE", "INITIALLY",
"REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE"); "REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
(TailMatches("DEFERRABLE") || TailMatches("INITIALLY", "IMMEDIATE|DEFERRED"))) (TailMatches("DEFERRABLE") || TailMatches("INITIALLY", "IMMEDIATE|DEFERRED")))
{ {
if (pset.sversion >= 110000) if (pset.sversion >= 110000)
...@@ -2753,11 +2779,16 @@ psql_completion(const char *text, int start, int end) ...@@ -2753,11 +2779,16 @@ psql_completion(const char *text, int start, int end)
else else
COMPLETE_WITH("REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE"); COMPLETE_WITH("REFERENCING", "FOR", "WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("REFERENCING")) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("REFERENCING"))
COMPLETE_WITH("OLD TABLE", "NEW TABLE"); COMPLETE_WITH("OLD TABLE", "NEW TABLE");
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("OLD|NEW", "TABLE")) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("OLD|NEW", "TABLE"))
COMPLETE_WITH("AS"); COMPLETE_WITH("AS");
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
(TailMatches("REFERENCING", "OLD", "TABLE", "AS", MatchAny) || (TailMatches("REFERENCING", "OLD", "TABLE", "AS", MatchAny) ||
TailMatches("REFERENCING", "OLD", "TABLE", MatchAny))) TailMatches("REFERENCING", "OLD", "TABLE", MatchAny)))
{ {
...@@ -2766,7 +2797,8 @@ psql_completion(const char *text, int start, int end) ...@@ -2766,7 +2797,8 @@ psql_completion(const char *text, int start, int end)
else else
COMPLETE_WITH("NEW TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE"); COMPLETE_WITH("NEW TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
(TailMatches("REFERENCING", "NEW", "TABLE", "AS", MatchAny) || (TailMatches("REFERENCING", "NEW", "TABLE", "AS", MatchAny) ||
TailMatches("REFERENCING", "NEW", "TABLE", MatchAny))) TailMatches("REFERENCING", "NEW", "TABLE", MatchAny)))
{ {
...@@ -2775,7 +2807,8 @@ psql_completion(const char *text, int start, int end) ...@@ -2775,7 +2807,8 @@ psql_completion(const char *text, int start, int end)
else else
COMPLETE_WITH("OLD TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE"); COMPLETE_WITH("OLD TABLE", "FOR", "WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
(TailMatches("REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || (TailMatches("REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) ||
TailMatches("REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) || TailMatches("REFERENCING", "OLD|NEW", "TABLE", MatchAny, "OLD|NEW", "TABLE", "AS", MatchAny) ||
TailMatches("REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", MatchAny) || TailMatches("REFERENCING", "OLD|NEW", "TABLE", "AS", MatchAny, "OLD|NEW", "TABLE", MatchAny) ||
...@@ -2786,11 +2819,16 @@ psql_completion(const char *text, int start, int end) ...@@ -2786,11 +2819,16 @@ psql_completion(const char *text, int start, int end)
else else
COMPLETE_WITH("FOR", "WHEN (", "EXECUTE PROCEDURE"); COMPLETE_WITH("FOR", "WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("FOR")) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("FOR"))
COMPLETE_WITH("EACH", "ROW", "STATEMENT"); COMPLETE_WITH("EACH", "ROW", "STATEMENT");
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("FOR", "EACH")) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("FOR", "EACH"))
COMPLETE_WITH("ROW", "STATEMENT"); COMPLETE_WITH("ROW", "STATEMENT");
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
(TailMatches("FOR", "EACH", "ROW|STATEMENT") || (TailMatches("FOR", "EACH", "ROW|STATEMENT") ||
TailMatches("FOR", "ROW|STATEMENT"))) TailMatches("FOR", "ROW|STATEMENT")))
{ {
...@@ -2799,22 +2837,31 @@ psql_completion(const char *text, int start, int end) ...@@ -2799,22 +2837,31 @@ psql_completion(const char *text, int start, int end)
else else
COMPLETE_WITH("WHEN (", "EXECUTE PROCEDURE"); COMPLETE_WITH("WHEN (", "EXECUTE PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("WHEN", "(*)")) else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("WHEN", "(*)"))
{ {
if (pset.sversion >= 110000) if (pset.sversion >= 110000)
COMPLETE_WITH("EXECUTE FUNCTION"); COMPLETE_WITH("EXECUTE FUNCTION");
else else
COMPLETE_WITH("EXECUTE PROCEDURE"); COMPLETE_WITH("EXECUTE PROCEDURE");
} }
/* complete CREATE TRIGGER ... EXECUTE with PROCEDURE|FUNCTION */
else if (HeadMatches("CREATE", "TRIGGER") && TailMatches("EXECUTE")) /*
* Complete CREATE [ OR REPLACE ] TRIGGER ... EXECUTE with
* PROCEDURE|FUNCTION.
*/
else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("EXECUTE"))
{ {
if (pset.sversion >= 110000) if (pset.sversion >= 110000)
COMPLETE_WITH("FUNCTION"); COMPLETE_WITH("FUNCTION");
else else
COMPLETE_WITH("PROCEDURE"); COMPLETE_WITH("PROCEDURE");
} }
else if (HeadMatches("CREATE", "TRIGGER") && else if ((HeadMatches("CREATE", "TRIGGER") ||
HeadMatches("CREATE", "OR", "REPLACE", "TRIGGER")) &&
TailMatches("EXECUTE", "FUNCTION|PROCEDURE")) TailMatches("EXECUTE", "FUNCTION|PROCEDURE"))
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL); COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
......
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