Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5953c99

Browse files
committed
Improve tab completion of CREATE EVENT TRIGGER in psql
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/[email protected]
1 parent 292ef6e commit 5953c99

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bin/psql/tab-complete.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,29 @@ psql_completion(const char *text, int start, int end)
26082608
/* Complete CREATE EVENT TRIGGER <name> ON with event_type */
26092609
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON"))
26102610
COMPLETE_WITH("ddl_command_start", "ddl_command_end", "sql_drop");
2611+
/*
2612+
* Complete CREATE EVENT TRIGGER <name> ON <event_type>. EXECUTE FUNCTION
2613+
* is the recommended grammar instead of EXECUTE PROCEDURE in version 11
2614+
* and upwards.
2615+
*/
2616+
else if (Matches("CREATE", "EVENT", "TRIGGER", MatchAny, "ON", MatchAny))
2617+
{
2618+
if (pset.sversion >= 110000)
2619+
COMPLETE_WITH("WHEN TAG IN (", "EXECUTE FUNCTION");
2620+
else
2621+
COMPLETE_WITH("WHEN TAG IN (", "EXECUTE PROCEDURE");
2622+
}
2623+
else if (HeadMatches("CREATE", "EVENT", "TRIGGER") &&
2624+
TailMatches("WHEN|AND", MatchAny, "IN", "(*)"))
2625+
{
2626+
if (pset.sversion >= 110000)
2627+
COMPLETE_WITH("EXECUTE FUNCTION");
2628+
else
2629+
COMPLETE_WITH("EXECUTE PROCEDURE");
2630+
}
2631+
else if (HeadMatches("CREATE", "EVENT", "TRIGGER") &&
2632+
TailMatches("EXECUTE", "FUNCTION|PROCEDURE"))
2633+
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
26112634

26122635
/* DEALLOCATE */
26132636
else if (Matches("DEALLOCATE"))

0 commit comments

Comments
 (0)