Patch: add psql tab completion for event triggers

Started by Ian Barwickalmost 12 years ago6 messages
#1Ian Barwick
ian@2ndquadrant.com
1 attachment(s)

As it was kind of annoying not to have this when playing around with
event triggers.

This also tightens up the existing tab completion for ALTER TRIGGER,
which contained redundant code for table name completion, and which was
also causing a spurious "RENAME TO" to be inserted in this context:

CREATE EVENT TRIGGER foo ON {event} ^I

Regards

Ian Barwick

--
Ian Barwick http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

psql-event-trigger.patchtext/x-patch; name=psql-event-trigger.patchDownload
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
new file mode 100644
index 6e2fbda..b5807f3
*** a/doc/src/sgml/func.sgml
--- b/doc/src/sgml/func.sgml
*************** FOR EACH ROW EXECUTE PROCEDURE suppress_
*** 17446,17452 ****
     </para>
  
     <para>
!     <function>pg_event_trigger_dropped_objects</> returns a list of all object
      dropped by the command in whose <literal>sql_drop</> event it is called.
      If called in any other context,
      <function>pg_event_trigger_dropped_objects</> raises an error.
--- 17446,17452 ----
     </para>
  
     <para>
!     <function>pg_event_trigger_dropped_objects</> returns a list of all objects
      dropped by the command in whose <literal>sql_drop</> event it is called.
      If called in any other context,
      <function>pg_event_trigger_dropped_objects</> raises an error.
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 202ffce..7179642
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 714,721 ****
  "   FROM pg_catalog.pg_prepared_statements "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
  
  /*
!  * This is a list of all "things" in Pgsql, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
   */
  
--- 714,726 ----
  "   FROM pg_catalog.pg_prepared_statements "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
  
+ #define Query_for_list_of_event_triggers \
+ " SELECT pg_catalog.quote_ident(evtname) "\
+ "   FROM pg_catalog.pg_event_trigger "\
+ "  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
+ 
  /*
!  * This is a list of all "things" in Postgres, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
   */
  
*************** static const pgsql_thing_t words_after_c
*** 746,751 ****
--- 751,757 ----
  	{"DATABASE", Query_for_list_of_databases},
  	{"DICTIONARY", Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
  	{"DOMAIN", NULL, &Query_for_list_of_domains},
+ 	{"EVENT TRIGGER", NULL, NULL},
  	{"EXTENSION", Query_for_list_of_extensions},
  	{"FOREIGN DATA WRAPPER", NULL, NULL},
  	{"FOREIGN TABLE", NULL, NULL},
*************** psql_completion(const char *text, int st
*** 934,942 ****
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
! 			 "ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
  		"USER", "USER MAPPING FOR", "VIEW", NULL};
  
--- 940,948 ----
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EXTENSION", "EVENT TRIGGER", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
! 			"ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
  		"USER", "USER MAPPING FOR", "VIEW", NULL};
  
*************** psql_completion(const char *text, int st
*** 1013,1018 ****
--- 1019,1055 ----
  		COMPLETE_WITH_LIST(list_ALTEREXTENSION);
  	}
  
+ 	/* ALTER EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> */
+ 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER[] =
+ 			{"DISABLE", "ENABLE", "OWNER TO", "RENAME TO", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> ENABLE */
+ 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ENABLE") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER_ENABLE[] =
+ 			{"REPLICA", "ALWAYS", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER_ENABLE);
+ 	}
+ 
  	/* ALTER FOREIGN */
  	else if (pg_strcasecmp(prev2_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev_wd, "FOREIGN") == 0)
*************** psql_completion(const char *text, int st
*** 1318,1340 ****
  			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
  		COMPLETE_WITH_CONST("ON");
  
- 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
- 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0)
- 	{
- 		completion_info_charp = prev2_wd;
- 		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
- 	}
- 
  	/*
! 	 * If we have ALTER TRIGGER <sth> ON, then add the correct tablename
  	 */
  	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
--- 1355,1374 ----
  			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
  		COMPLETE_WITH_CONST("ON");
  
  	/*
! 	 * If we have ALTER TRIGGER <name> ON, then add the correct tablename
  	 */
  	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
! 	{
! 		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
! 	}
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
! 			 pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
*************** psql_completion(const char *text, int st
*** 1877,1883 ****
  	{
  		static const char *const list_COMMENT[] =
  		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION",
! 			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
  			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
--- 1911,1917 ----
  	{
  		static const char *const list_COMMENT[] =
  		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION",
! 		 "EVENT TRIGGER", "FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
  			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
*************** psql_completion(const char *text, int st
*** 1885,1890 ****
--- 1919,1931 ----
  
  		COMPLETE_WITH_LIST(list_COMMENT);
  	}
+ 	else if (pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
  	else if (pg_strcasecmp(prev3_wd, "COMMENT") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0 &&
  			 pg_strcasecmp(prev_wd, "FOREIGN") == 0)
*************** psql_completion(const char *text, int st
*** 2354,2359 ****
--- 2395,2421 ----
  			 pg_strcasecmp(prev_wd, "AS") == 0)
  		COMPLETE_WITH_CONST("SELECT");
  
+ /* CREATE EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	/* Complete CREATE EVENT TRIGGER <name> with ON */
+ 	else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 		COMPLETE_WITH_CONST("ON");
+ 	/* Complete CREATE EVENT TRIGGER <name> ON with event type */
+ 	else if (pg_strcasecmp(prev5_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ON") == 0)
+ 	{
+ 		static const char *const list_CREATE_EVENT_TRIGGER_ON[] =
+ 		{"ddl_command_start", "ddl_command_end", "sql_drop", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_CREATE_EVENT_TRIGGER_ON);
+ 	}
+ 
  /* DECLARE */
  	else if (pg_strcasecmp(prev2_wd, "DECLARE") == 0)
  	{
*************** psql_completion(const char *text, int st
*** 2372,2378 ****
  		COMPLETE_WITH_LIST(list_DECLARECURSOR);
  	}
  
- 
  /* DELETE */
  
  	/*
--- 2434,2439 ----
*************** psql_completion(const char *text, int st
*** 2446,2451 ****
--- 2507,2515 ----
  			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 &&
  			  prev_wd[strlen(prev_wd) - 1] == ')') ||
+ 			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
+ 			  pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			  pg_strcasecmp(prev2_wd, "TRIGGER") == 0) ||
  			 (pg_strcasecmp(prev5_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
  			  pg_strcasecmp(prev3_wd, "DATA") == 0 &&
*************** psql_completion(const char *text, int st
*** 2494,2504 ****
--- 2558,2570 ----
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
  	}
  
+ 	/* DROP AGGREGATE FUNCTION */
  	else if (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
  			 (pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 ||
  			  pg_strcasecmp(prev3_wd, "FUNCTION") == 0) &&
  			 pg_strcasecmp(prev_wd, "(") == 0)
  		COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+ 
  	/* DROP OWNED BY */
  	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
  			 pg_strcasecmp(prev_wd, "OWNED") == 0)
*************** psql_completion(const char *text, int st
*** 2511,2523 ****
  			 pg_strcasecmp(prev2_wd, "TEXT") == 0 &&
  			 pg_strcasecmp(prev_wd, "SEARCH") == 0)
  	{
- 
  		static const char *const list_ALTERTEXTSEARCH[] =
  		{"CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE", NULL};
  
  		COMPLETE_WITH_LIST(list_ALTERTEXTSEARCH);
  	}
  
  /* EXECUTE, but not EXECUTE embedded in other commands */
  	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
  			 prev2_wd[0] == '\0')
--- 2577,2601 ----
  			 pg_strcasecmp(prev2_wd, "TEXT") == 0 &&
  			 pg_strcasecmp(prev_wd, "SEARCH") == 0)
  	{
  		static const char *const list_ALTERTEXTSEARCH[] =
  		{"CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE", NULL};
  
  		COMPLETE_WITH_LIST(list_ALTERTEXTSEARCH);
  	}
  
+ 	/* DROP EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 	{
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	}
+ 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
  /* EXECUTE, but not EXECUTE embedded in other commands */
  	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
  			 prev2_wd[0] == '\0')
#2Ian Barwick
ian@2ndquadrant.com
In reply to: Ian Barwick (#1)
1 attachment(s)
Re: Patch: add psql tab completion for event triggers

On 08/04/14 18:22, Ian Barwick wrote:

As it was kind of annoying not to have this when playing around with
event triggers.

This also tightens up the existing tab completion for ALTER TRIGGER,
which contained redundant code for table name completion, and which was
also causing a spurious "RENAME TO" to be inserted in this context:

CREATE EVENT TRIGGER foo ON {event} ^I

Apologies, previous patch had some unrelated changes in it.

Correct patch attached.

--
Ian Barwick http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

psql-event-trigger.patchtext/x-patch; name=psql-event-trigger.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 202ffce..7179642
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 714,721 ****
  "   FROM pg_catalog.pg_prepared_statements "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
  
  /*
!  * This is a list of all "things" in Pgsql, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
   */
  
--- 714,726 ----
  "   FROM pg_catalog.pg_prepared_statements "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
  
+ #define Query_for_list_of_event_triggers \
+ " SELECT pg_catalog.quote_ident(evtname) "\
+ "   FROM pg_catalog.pg_event_trigger "\
+ "  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
+ 
  /*
!  * This is a list of all "things" in Postgres, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
   */
  
*************** static const pgsql_thing_t words_after_c
*** 746,751 ****
--- 751,757 ----
  	{"DATABASE", Query_for_list_of_databases},
  	{"DICTIONARY", Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
  	{"DOMAIN", NULL, &Query_for_list_of_domains},
+ 	{"EVENT TRIGGER", NULL, NULL},
  	{"EXTENSION", Query_for_list_of_extensions},
  	{"FOREIGN DATA WRAPPER", NULL, NULL},
  	{"FOREIGN TABLE", NULL, NULL},
*************** psql_completion(const char *text, int st
*** 934,942 ****
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
! 			 "ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
  		"USER", "USER MAPPING FOR", "VIEW", NULL};
  
--- 940,948 ----
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EXTENSION", "EVENT TRIGGER", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
! 			"ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
  		"USER", "USER MAPPING FOR", "VIEW", NULL};
  
*************** psql_completion(const char *text, int st
*** 1013,1018 ****
--- 1019,1055 ----
  		COMPLETE_WITH_LIST(list_ALTEREXTENSION);
  	}
  
+ 	/* ALTER EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> */
+ 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER[] =
+ 			{"DISABLE", "ENABLE", "OWNER TO", "RENAME TO", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> ENABLE */
+ 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ENABLE") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER_ENABLE[] =
+ 			{"REPLICA", "ALWAYS", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER_ENABLE);
+ 	}
+ 
  	/* ALTER FOREIGN */
  	else if (pg_strcasecmp(prev2_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev_wd, "FOREIGN") == 0)
*************** psql_completion(const char *text, int st
*** 1318,1340 ****
  			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
  		COMPLETE_WITH_CONST("ON");
  
- 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
- 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0)
- 	{
- 		completion_info_charp = prev2_wd;
- 		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
- 	}
- 
  	/*
! 	 * If we have ALTER TRIGGER <sth> ON, then add the correct tablename
  	 */
  	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
! 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
--- 1355,1374 ----
  			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
  		COMPLETE_WITH_CONST("ON");
  
  	/*
! 	 * If we have ALTER TRIGGER <name> ON, then add the correct tablename
  	 */
  	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev_wd, "ON") == 0)
! 	{
! 		completion_info_charp = prev2_wd;
! 		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
! 	}
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
! 			 pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
*************** psql_completion(const char *text, int st
*** 1877,1883 ****
  	{
  		static const char *const list_COMMENT[] =
  		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION",
! 			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
  			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
--- 1911,1917 ----
  	{
  		static const char *const list_COMMENT[] =
  		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION",
! 		 "EVENT TRIGGER", "FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
  			"OPERATOR", "TRIGGER", "CONSTRAINT", "DOMAIN", "LARGE OBJECT",
*************** psql_completion(const char *text, int st
*** 1885,1890 ****
--- 1919,1931 ----
  
  		COMPLETE_WITH_LIST(list_COMMENT);
  	}
+ 	else if (pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
  	else if (pg_strcasecmp(prev3_wd, "COMMENT") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0 &&
  			 pg_strcasecmp(prev_wd, "FOREIGN") == 0)
*************** psql_completion(const char *text, int st
*** 2354,2359 ****
--- 2395,2421 ----
  			 pg_strcasecmp(prev_wd, "AS") == 0)
  		COMPLETE_WITH_CONST("SELECT");
  
+ /* CREATE EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	/* Complete CREATE EVENT TRIGGER <name> with ON */
+ 	else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 		COMPLETE_WITH_CONST("ON");
+ 	/* Complete CREATE EVENT TRIGGER <name> ON with event type */
+ 	else if (pg_strcasecmp(prev5_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ON") == 0)
+ 	{
+ 		static const char *const list_CREATE_EVENT_TRIGGER_ON[] =
+ 		{"ddl_command_start", "ddl_command_end", "sql_drop", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_CREATE_EVENT_TRIGGER_ON);
+ 	}
+ 
  /* DECLARE */
  	else if (pg_strcasecmp(prev2_wd, "DECLARE") == 0)
  	{
*************** psql_completion(const char *text, int st
*** 2372,2378 ****
  		COMPLETE_WITH_LIST(list_DECLARECURSOR);
  	}
  
- 
  /* DELETE */
  
  	/*
--- 2434,2439 ----
*************** psql_completion(const char *text, int st
*** 2446,2451 ****
--- 2507,2515 ----
  			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 &&
  			  prev_wd[strlen(prev_wd) - 1] == ')') ||
+ 			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
+ 			  pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			  pg_strcasecmp(prev2_wd, "TRIGGER") == 0) ||
  			 (pg_strcasecmp(prev5_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
  			  pg_strcasecmp(prev3_wd, "DATA") == 0 &&
*************** psql_completion(const char *text, int st
*** 2494,2504 ****
--- 2558,2570 ----
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
  	}
  
+ 	/* DROP AGGREGATE FUNCTION */
  	else if (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
  			 (pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 ||
  			  pg_strcasecmp(prev3_wd, "FUNCTION") == 0) &&
  			 pg_strcasecmp(prev_wd, "(") == 0)
  		COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+ 
  	/* DROP OWNED BY */
  	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
  			 pg_strcasecmp(prev_wd, "OWNED") == 0)
*************** psql_completion(const char *text, int st
*** 2511,2523 ****
  			 pg_strcasecmp(prev2_wd, "TEXT") == 0 &&
  			 pg_strcasecmp(prev_wd, "SEARCH") == 0)
  	{
- 
  		static const char *const list_ALTERTEXTSEARCH[] =
  		{"CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE", NULL};
  
  		COMPLETE_WITH_LIST(list_ALTERTEXTSEARCH);
  	}
  
  /* EXECUTE, but not EXECUTE embedded in other commands */
  	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
  			 prev2_wd[0] == '\0')
--- 2577,2601 ----
  			 pg_strcasecmp(prev2_wd, "TEXT") == 0 &&
  			 pg_strcasecmp(prev_wd, "SEARCH") == 0)
  	{
  		static const char *const list_ALTERTEXTSEARCH[] =
  		{"CONFIGURATION", "DICTIONARY", "PARSER", "TEMPLATE", NULL};
  
  		COMPLETE_WITH_LIST(list_ALTERTEXTSEARCH);
  	}
  
+ 	/* DROP EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 	{
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	}
+ 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
  /* EXECUTE, but not EXECUTE embedded in other commands */
  	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
  			 prev2_wd[0] == '\0')
#3Robert Haas
robertmhaas@gmail.com
In reply to: Ian Barwick (#2)
Re: Patch: add psql tab completion for event triggers

On Tue, Apr 8, 2014 at 5:27 AM, Ian Barwick <ian@2ndquadrant.com> wrote:

On 08/04/14 18:22, Ian Barwick wrote:

As it was kind of annoying not to have this when playing around with
event triggers.

This also tightens up the existing tab completion for ALTER TRIGGER,
which contained redundant code for table name completion, and which was
also causing a spurious "RENAME TO" to be inserted in this context:

CREATE EVENT TRIGGER foo ON {event} ^I

Apologies, previous patch had some unrelated changes in it.

Correct patch attached.

This *still* has some unrelated things in it, like s/Pgsql/Postgres/,
and numerous hunks consisting entirely of whitespace changes and/or
changes to unrelated comments.

Also, what's the point of this hunk:

*************** psql_completion(const char *text, int st
*** 1318,1340 ****
pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
COMPLETE_WITH_CONST("ON");

- else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
- pg_strcasecmp(prev3_wd, "TRIGGER") == 0)
- {
- completion_info_charp = prev2_wd;
- COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
- }
-
/*
! * If we have ALTER TRIGGER <sth> ON, then add the correct tablename
*/
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
! COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);

/* ALTER TRIGGER <name> ON <name> */
! else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev2_wd, "ON") == 0)
COMPLETE_WITH_CONST("RENAME TO");

--- 1355,1374 ----
                         pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
                COMPLETE_WITH_CONST("ON");

/*
! * If we have ALTER TRIGGER <name> ON, then add the correct tablename
*/
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
! {
! completion_info_charp = prev2_wd;
! COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
! }

/* ALTER TRIGGER <name> ON <name> */
! else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
! pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev2_wd, "ON") == 0)
COMPLETE_WITH_CONST("RENAME TO");

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Ian Barwick
ian@2ndquadrant.com
In reply to: Robert Haas (#3)
1 attachment(s)
Re: Patch: add psql tab completion for event triggers

On 10/04/14 00:23, Robert Haas wrote:

On Tue, Apr 8, 2014 at 5:27 AM, Ian Barwick <ian@2ndquadrant.com> wrote:

On 08/04/14 18:22, Ian Barwick wrote:

As it was kind of annoying not to have this when playing around with
event triggers.

This also tightens up the existing tab completion for ALTER TRIGGER,
which contained redundant code for table name completion, and which was
also causing a spurious "RENAME TO" to be inserted in this context:

CREATE EVENT TRIGGER foo ON {event} ^I

Apologies, previous patch had some unrelated changes in it.

Correct patch attached.

This *still* has some unrelated things in it, like s/Pgsql/Postgres/,
and numerous hunks consisting entirely of whitespace changes and/or
changes to unrelated comments.

Apologies again, that was ill-thought out. Revised patch attached with
only the additions related to event triggers, and the small fix for
ALTER TRIGGER mentioned above which ensures "RENAME TO" is applied only
when "ALTER TRIGGER <name> ON <sth>" was input; currently there is no
check for a preceding "ALTER", resulting in the spurious "RENAME TO"
when completing "CREATE EVENT TRIGGER".

Also, what's the point of this hunk:

*************** psql_completion(const char *text, int st
*** 1318,1340 ****
pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
COMPLETE_WITH_CONST("ON");

- else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
- pg_strcasecmp(prev3_wd, "TRIGGER") == 0)
- {
- completion_info_charp = prev2_wd;
- COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
- }
-
/*
! * If we have ALTER TRIGGER <sth> ON, then add the correct tablename
*/
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
! COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);

/* ALTER TRIGGER <name> ON <name> */
! else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev2_wd, "ON") == 0)
COMPLETE_WITH_CONST("RENAME TO");

--- 1355,1374 ----
pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
COMPLETE_WITH_CONST("ON");

/*
! * If we have ALTER TRIGGER <name> ON, then add the correct tablename
*/
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
! {
! completion_info_charp = prev2_wd;
! COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
! }

/* ALTER TRIGGER <name> ON <name> */
! else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
! pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev2_wd, "ON") == 0)
COMPLETE_WITH_CONST("RENAME TO");

I'll submit that as a separate patch. This was intended to fix this:

else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0)
{
completion_info_charp = prev2_wd;
COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger);
}

/*
* If we have ALTER TRIGGER <sth> ON, then add the correct tablename
*/
else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
pg_strcasecmp(prev_wd, "ON") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);

as the second "else if" clause is redundant.

Regards

Ian Barwick

--
Ian Barwick http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

psql-event-trigger.v1.patchtext/x-patch; name=psql-event-trigger.v1.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 202ffce..6d26ffc
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
*************** static const SchemaQuery Query_for_list_
*** 714,719 ****
--- 714,724 ----
  "   FROM pg_catalog.pg_prepared_statements "\
  "  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
  
+ #define Query_for_list_of_event_triggers \
+ " SELECT pg_catalog.quote_ident(evtname) "\
+ "   FROM pg_catalog.pg_event_trigger "\
+ "  WHERE substring(pg_catalog.quote_ident(evtname),1,%d)='%s'"
+ 
  /*
   * This is a list of all "things" in Pgsql, which can show up after CREATE or
   * DROP; and there is also a query to get a list of them.
*************** static const pgsql_thing_t words_after_c
*** 746,751 ****
--- 751,757 ----
  	{"DATABASE", Query_for_list_of_databases},
  	{"DICTIONARY", Query_for_list_of_ts_dictionaries, NULL, THING_NO_SHOW},
  	{"DOMAIN", NULL, &Query_for_list_of_domains},
+ 	{"EVENT TRIGGER", NULL, NULL},
  	{"EXTENSION", Query_for_list_of_extensions},
  	{"FOREIGN DATA WRAPPER", NULL, NULL},
  	{"FOREIGN TABLE", NULL, NULL},
*************** psql_completion(const char *text, int st
*** 934,940 ****
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
  			 "ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
--- 940,946 ----
  	{
  		static const char *const list_ALTER[] =
  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN",
! 			"EVENT TRIGGER", "EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION",
  			"GROUP", "INDEX", "LANGUAGE", "LARGE OBJECT", "MATERIALIZED VIEW", "OPERATOR",
  			 "ROLE", "RULE", "SCHEMA", "SERVER", "SEQUENCE", "SYSTEM SET", "TABLE",
  			"TABLESPACE", "TEXT SEARCH", "TRIGGER", "TYPE",
*************** psql_completion(const char *text, int st
*** 1003,1008 ****
--- 1009,1045 ----
  		COMPLETE_WITH_LIST(list_ALTERDATABASE);
  	}
  
+ 	/* ALTER EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> */
+ 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER[] =
+ 			{"DISABLE", "ENABLE", "OWNER TO", "RENAME TO", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER);
+ 	}
+ 
+ 	/* ALTER EVENT TRIGGER <name> ENABLE */
+ 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ENABLE") == 0)
+ 	{
+ 		static const char *const list_ALTER_EVENT_TRIGGER_ENABLE[] =
+ 			{"REPLICA", "ALWAYS", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_ALTER_EVENT_TRIGGER_ENABLE);
+ 	}
+ 
  	/* ALTER EXTENSION <name> */
  	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "EXTENSION") == 0)
*************** psql_completion(const char *text, int st
*** 1334,1340 ****
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
--- 1371,1378 ----
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
  
  	/* ALTER TRIGGER <name> ON <name> */
! 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
! 			 pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
  			 pg_strcasecmp(prev2_wd, "ON") == 0)
  		COMPLETE_WITH_CONST("RENAME TO");
  
*************** psql_completion(const char *text, int st
*** 1876,1882 ****
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		static const char *const list_COMMENT[] =
! 		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION",
  			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
--- 1914,1920 ----
  			 pg_strcasecmp(prev_wd, "ON") == 0)
  	{
  		static const char *const list_COMMENT[] =
! 		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EVENT TRIGGER", "EXTENSION",
  			"FOREIGN DATA WRAPPER", "FOREIGN TABLE",
  			"SERVER", "INDEX", "LANGUAGE", "RULE", "SCHEMA", "SEQUENCE",
  			"TABLE", "TYPE", "VIEW", "MATERIALIZED VIEW", "COLUMN", "AGGREGATE", "FUNCTION",
*************** psql_completion(const char *text, int st
*** 1931,1936 ****
--- 1969,1981 ----
  	{
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
  	}
+ 	else if (pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
  	else if ((pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
  			  pg_strcasecmp(prev3_wd, "ON") == 0) ||
  			 (pg_strcasecmp(prev5_wd, "COMMENT") == 0 &&
*************** psql_completion(const char *text, int st
*** 2354,2359 ****
--- 2399,2425 ----
  			 pg_strcasecmp(prev_wd, "AS") == 0)
  		COMPLETE_WITH_CONST("SELECT");
  
+ /* CREATE EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	/* Complete CREATE EVENT TRIGGER <name> with ON */
+ 	else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "TRIGGER") == 0)
+ 		COMPLETE_WITH_CONST("ON");
+ 	/* Complete CREATE EVENT TRIGGER <name> ON with event_type */
+ 	else if (pg_strcasecmp(prev5_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev4_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "TRIGGER") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "ON") == 0)
+ 	{
+ 		static const char *const list_CREATE_EVENT_TRIGGER_ON[] =
+ 		{"ddl_command_start", "ddl_command_end", "sql_drop", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_CREATE_EVENT_TRIGGER_ON);
+ 	}
+ 
  /* DECLARE */
  	else if (pg_strcasecmp(prev2_wd, "DECLARE") == 0)
  	{
*************** psql_completion(const char *text, int st
*** 2446,2451 ****
--- 2512,2520 ----
  			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 &&
  			  prev_wd[strlen(prev_wd) - 1] == ')') ||
+ 			 (pg_strcasecmp(prev4_wd, "DROP") == 0 &&
+ 			  pg_strcasecmp(prev3_wd, "EVENT") == 0 &&
+ 			  pg_strcasecmp(prev2_wd, "TRIGGER") == 0) ||
  			 (pg_strcasecmp(prev5_wd, "DROP") == 0 &&
  			  pg_strcasecmp(prev4_wd, "FOREIGN") == 0 &&
  			  pg_strcasecmp(prev3_wd, "DATA") == 0 &&
*************** psql_completion(const char *text, int st
*** 2518,2523 ****
--- 2587,2605 ----
  		COMPLETE_WITH_LIST(list_ALTERTEXTSEARCH);
  	}
  
+ 	/* DROP EVENT TRIGGER */
+ 	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "EVENT") == 0)
+ 	{
+ 		COMPLETE_WITH_CONST("TRIGGER");
+ 	}
+ 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
+ 	{
+ 		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+ 	}
+ 
  /* EXECUTE, but not EXECUTE embedded in other commands */
  	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
  			 prev2_wd[0] == '\0')
#5Robert Haas
robertmhaas@gmail.com
In reply to: Ian Barwick (#4)
Re: Patch: add psql tab completion for event triggers

On Wed, Apr 9, 2014 at 8:58 PM, Ian Barwick <ian@2ndquadrant.com> wrote:

Apologies again, that was ill-thought out. Revised patch attached with only
the additions related to event triggers, and the small fix for ALTER TRIGGER
mentioned above which ensures "RENAME TO" is applied only when "ALTER
TRIGGER <name> ON <sth>" was input; currently there is no check for a
preceding "ALTER", resulting in the spurious "RENAME TO" when completing
"CREATE EVENT TRIGGER".

OK, committed.

(I know this was submitted rather late, but I think we've often
allowed tab-completion fixups at similar times in past releases, since
they are quite mechanical. If anyone feels that I shouldn't have
committed this, please advise.)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Michael Paquier
michael.paquier@gmail.com
In reply to: Robert Haas (#5)
Re: Patch: add psql tab completion for event triggers

On Mon, Apr 14, 2014 at 9:46 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Wed, Apr 9, 2014 at 8:58 PM, Ian Barwick <ian@2ndquadrant.com> wrote:

Apologies again, that was ill-thought out. Revised patch attached with only
the additions related to event triggers, and the small fix for ALTER TRIGGER
mentioned above which ensures "RENAME TO" is applied only when "ALTER
TRIGGER <name> ON <sth>" was input; currently there is no check for a
preceding "ALTER", resulting in the spurious "RENAME TO" when completing
"CREATE EVENT TRIGGER".

OK, committed.

(I know this was submitted rather late, but I think we've often
allowed tab-completion fixups at similar times in past releases, since
they are quite mechanical. If anyone feels that I shouldn't have
committed this, please advise.)

+1 for this change even if it came late in-game. Patch is
straight-forward, and this is always useful to have.
-- 
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers