From 5953c99697621174f50aa219a3cd457212968268 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 26 Oct 2018 13:46:20 +0900 Subject: [PATCH] Improve tab completion of CREATE EVENT TRIGGER in psql MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This adds tab completion of the clauses WHEN and EXECUTE FUNCTION|PROCEDURE clauses to CREATE EVENT TRIGGER, similar to CREATE TRIGGER in the previous commit. This has version-dependent logic so as FUNCTION is chosen over PROCEDURE for 11 and newer versions. Author: Dagfinn Ilmari Mannsåker Reviewed-by: Tom Lane, Michael Paquier Discussion: https://postgr.es/m/d8jmur4q4yc.fsf@dalvik.ping.uio.no --- src/bin/psql/tab-complete.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 4200574079..a980f92e11 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2608,6 +2608,29 @@ psql_completion(const char *text, int start, int end) /* Complete CREATE EVENT TRIGGER ON with event_type */ else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON")) COMPLETE_WITH("ddl_command_start", "ddl_command_end", "sql_drop"); + /* + * Complete CREATE EVENT TRIGGER ON . EXECUTE FUNCTION + * is the recommended grammar instead of EXECUTE PROCEDURE in version 11 + * and upwards. + */ + else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON", MatchAny)) + { + if (pset.sversion >= 110000) + COMPLETE_WITH("WHEN TAG IN (", "EXECUTE FUNCTION"); + else + COMPLETE_WITH("WHEN TAG IN (", "EXECUTE PROCEDURE"); + } + else if (HeadMatches("CREATE", "EVENT", "TRIGGER") && + TailMatches("WHEN|AND", MatchAny, "IN", "(*)")) + { + if (pset.sversion >= 110000) + COMPLETE_WITH("EXECUTE FUNCTION"); + else + COMPLETE_WITH("EXECUTE PROCEDURE"); + } + else if (HeadMatches("CREATE", "EVENT", "TRIGGER") && + TailMatches("EXECUTE", "FUNCTION|PROCEDURE")) + COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL); /* DEALLOCATE */ else if (Matches("DEALLOCATE")) -- 2.40.0