diff options
| author | Robert Haas <rhaas@postgresql.org> | 2014-04-14 08:44:21 -0400 | 
|---|---|---|
| committer | Robert Haas <rhaas@postgresql.org> | 2014-04-14 08:44:21 -0400 | 
| commit | 7b979524afb21c969234f7a0a9b1c97ceec4629d (patch) | |
| tree | 50b0ab3d4dd49973962a335ce54bd1b0204a2a99 /src/bin/psql/tab-complete.c | |
| parent | e3e6e3af560116adc20cc9d6e75bfe82a45def60 (diff) | |
Tab completion for event triggers.
Ian Barwick
Diffstat (limited to 'src/bin/psql/tab-complete.c')
| -rw-r--r-- | src/bin/psql/tab-complete.c | 88 | 
1 files changed, 85 insertions, 3 deletions
| diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 202ffcef690..6d26ffcd7df 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -714,6 +714,11 @@ static const SchemaQuery Query_for_list_of_matviews = {  "   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. @@ -746,6 +751,7 @@ static const pgsql_thing_t words_after_create[] = {  	{"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}, @@ -934,7 +940,7 @@ psql_completion(const char *text, int start, int end)  	{  		static const char *const list_ALTER[] =  		{"AGGREGATE", "COLLATION", "CONVERSION", "DATABASE", "DEFAULT PRIVILEGES", "DOMAIN", -			"EXTENSION", "FOREIGN DATA WRAPPER", "FOREIGN TABLE", "FUNCTION", +			"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", @@ -1003,6 +1009,37 @@ psql_completion(const char *text, int start, int end)  		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) @@ -1334,7 +1371,8 @@ psql_completion(const char *text, int start, int end)  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);  	/* ALTER TRIGGER <name> ON <name> */ -	else if (pg_strcasecmp(prev4_wd, "TRIGGER") == 0 && +	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"); @@ -1876,7 +1914,7 @@ psql_completion(const char *text, int start, int end)  			 pg_strcasecmp(prev_wd, "ON") == 0)  	{  		static const char *const list_COMMENT[] = -		{"CAST", "COLLATION", "CONVERSION", "DATABASE", "EXTENSION", +		{"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", @@ -1931,6 +1969,13 @@ psql_completion(const char *text, int start, int end)  	{  		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 && @@ -2354,6 +2399,27 @@ psql_completion(const char *text, int start, int end)  			 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)  	{ @@ -2446,6 +2512,9 @@ psql_completion(const char *text, int start, int end)  			 (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 && @@ -2518,6 +2587,19 @@ psql_completion(const char *text, int start, int end)  		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') | 
