>From 2e49b1880df9790992953cd0bd9da2ec9cafece9 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Nov 2015 10:15:54 +0900
Subject: [PATCH 2/8] Simplify the usages of COMPLETE_WITH_QUERY

Many of the usage of COMPLETE_WITH_QUERY is accompanied by assignment
to completion_info_charp. This patch adds new second parameter to the
macro COMPLETE_WITH_QUERY according to COMPLETE_WITH_SCHEMA_QUERY so
that its usage looks simpler.
---
 src/bin/psql/tab-complete.c | 184 ++++++++++++++++++++------------------------
 1 file changed, 85 insertions(+), 99 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index b58ec14..55ace8a 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -144,9 +144,10 @@ static bool completion_case_sensitive;	/* completion is case sensitive */
  * 5) The list of attributes of the given table (possibly schema-qualified).
  * 6/ The list of arguments to the given function (possibly schema-qualified).
  */
-#define COMPLETE_WITH_QUERY(query) \
+#define COMPLETE_WITH_QUERY(query, info) \
 do { \
 	completion_charp = query; \
+	completion_info_charp = info; \
 	matches = completion_matches(text, complete_from_query); \
 } while (0)
 
@@ -1042,7 +1043,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "OWNED") == 0 &&
 			 pg_strcasecmp(prev4_wd, "BY") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	}
 	/* ALTER AGGREGATE,FUNCTION <name> */
 	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
@@ -1111,7 +1112,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers, NULL);
 	}
 
 	/* ALTER EVENT TRIGGER <name> */
@@ -1366,8 +1367,7 @@ psql_completion(const char *text, int start, int end)
 			  pg_strcasecmp(prev2_wd, "VALIDATE") == 0) &&
 			 pg_strcasecmp(prev_wd, "CONSTRAINT") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_constraint_of_type);
+		COMPLETE_WITH_QUERY(Query_for_constraint_of_type, prev3_wd);
 	}
 	/* ALTER DOMAIN <sth> RENAME */
 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
@@ -1438,7 +1438,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "SYSTEM") == 0 &&
 			 (pg_strcasecmp(prev_wd, "SET") == 0 ||
 			  pg_strcasecmp(prev_wd, "RESET") == 0))
-		COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars);
+		COMPLETE_WITH_QUERY(Query_for_list_of_alter_system_set_vars, NULL);
 	/* ALTER VIEW <name> */
 	else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev2_wd, "VIEW") == 0)
@@ -1483,7 +1483,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev5_wd, "POLICY") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
 			 pg_strcasecmp(prev_wd, "TO") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles, NULL);
 	/* ALTER POLICY <name> ON <table> USING ( */
 	else if (pg_strcasecmp(prev6_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev5_wd, "POLICY") == 0 &&
@@ -1507,8 +1507,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "RULE") == 0 &&
 			 pg_strcasecmp(prev_wd, "ON") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule, prev2_wd);
 	}
 
 	/* ALTER RULE <name> ON <name> */
@@ -1524,8 +1523,7 @@ psql_completion(const char *text, int start, int end)
 	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);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger, prev2_wd);
 	}
 
 	/*
@@ -1580,32 +1578,28 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "ENABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "RULE") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_rule_of_table);
+		COMPLETE_WITH_QUERY(Query_for_rule_of_table, prev3_wd);
 	}
 	else if (pg_strcasecmp(prev6_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev5_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ENABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "RULE") == 0)
 	{
-		completion_info_charp = prev4_wd;
-		COMPLETE_WITH_QUERY(Query_for_rule_of_table);
+		COMPLETE_WITH_QUERY(Query_for_rule_of_table, prev4_wd);
 	}
 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "ENABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
+		COMPLETE_WITH_QUERY(Query_for_trigger_of_table, prev3_wd);
 	}
 	else if (pg_strcasecmp(prev6_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev5_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ENABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		completion_info_charp = prev4_wd;
-		COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
+		COMPLETE_WITH_QUERY(Query_for_trigger_of_table, prev4_wd);
 	}
 	/* ALTER TABLE xxx INHERIT */
 	else if (pg_strcasecmp(prev4_wd, "ALTER") == 0 &&
@@ -1637,16 +1631,14 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "DISABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "RULE") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_rule_of_table);
+		COMPLETE_WITH_QUERY(Query_for_rule_of_table, prev3_wd);
 	}
 	else if (pg_strcasecmp(prev5_wd, "ALTER") == 0 &&
 			 pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "DISABLE") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_trigger_of_table);
+		COMPLETE_WITH_QUERY(Query_for_trigger_of_table, prev3_wd);
 	}
 	else if (pg_strcasecmp(prev4_wd, "DISABLE") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ROW") == 0 &&
@@ -1724,8 +1716,7 @@ psql_completion(const char *text, int start, int end)
 			  pg_strcasecmp(prev2_wd, "VALIDATE") == 0) &&
 			 pg_strcasecmp(prev_wd, "CONSTRAINT") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_constraint_of_table);
+		COMPLETE_WITH_QUERY(Query_for_constraint_of_table, prev3_wd);
 	}
 	/* ALTER TABLE ALTER [COLUMN] <foo> */
 	else if ((pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
@@ -1793,8 +1784,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "CLUSTER") == 0 &&
 			 pg_strcasecmp(prev_wd, "ON") == 0)
 	{
-		completion_info_charp = prev3_wd;
-		COMPLETE_WITH_QUERY(Query_for_index_of_table);
+		COMPLETE_WITH_QUERY(Query_for_index_of_table, prev3_wd);
 	}
 	/* If we have TABLE <sth> SET, provide list of attributes and '(' */
 	else if (pg_strcasecmp(prev3_wd, "TABLE") == 0 &&
@@ -1809,7 +1799,7 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "SET") == 0 &&
 			 pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces, NULL);
 	/* If we have TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */
 	else if (pg_strcasecmp(prev4_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "SET") == 0 &&
@@ -1870,8 +1860,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "USING") == 0 &&
 			 pg_strcasecmp(prev_wd, "INDEX") == 0)
 	{
-		completion_info_charp = prev5_wd;
-		COMPLETE_WITH_QUERY(Query_for_index_of_table);
+		COMPLETE_WITH_QUERY(Query_for_index_of_table, prev5_wd);
 	}
 	else if (pg_strcasecmp(prev5_wd, "TABLE") == 0 &&
 			 pg_strcasecmp(prev3_wd, "REPLICA") == 0 &&
@@ -2039,7 +2028,7 @@ psql_completion(const char *text, int start, int end)
 			 (pg_strcasecmp(prev2_wd, "ADD") == 0 ||
 			  pg_strcasecmp(prev2_wd, "DROP") == 0) &&
 			 pg_strcasecmp(prev_wd, "USER") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 
 /* BEGIN, END, ABORT */
 	else if (pg_strcasecmp(prev_wd, "BEGIN") == 0 ||
@@ -2106,8 +2095,7 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev3_wd, "CLUSTER") == 0 &&
 			 pg_strcasecmp(prev_wd, "USING") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_index_of_table);
+		COMPLETE_WITH_QUERY(Query_for_index_of_table, prev2_wd);
 	}
 
 	/*
@@ -2117,8 +2105,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "VERBOSE") == 0 &&
 			 pg_strcasecmp(prev_wd, "USING") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_index_of_table);
+		COMPLETE_WITH_QUERY(Query_for_index_of_table, prev2_wd);
 	}
 
 /* COMMENT */
@@ -2160,7 +2147,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "ON") == 0 &&
 			 pg_strcasecmp(prev_wd, "CONSTRAINT") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_all_table_constraints);
+		COMPLETE_WITH_QUERY(Query_for_all_table_constraints, NULL);
 	}
 	else if (pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
@@ -2173,8 +2160,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "CONSTRAINT") == 0 &&
 			 pg_strcasecmp(prev_wd, "ON") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_constraint);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_constraint, prev2_wd);
 	}
 	else if (pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
@@ -2188,7 +2174,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers, NULL);
 	}
 	else if (((pg_strcasecmp(prev4_wd, "COMMENT") == 0 &&
 			   pg_strcasecmp(prev3_wd, "ON") == 0) ||
@@ -2270,13 +2256,13 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
 			 pg_strcasecmp(prev3_wd, "DATABASE") == 0 &&
 			 pg_strcasecmp(prev_wd, "TEMPLATE") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_template_databases);
+		COMPLETE_WITH_QUERY(Query_for_list_of_template_databases, NULL);
 
 	/* CREATE EXTENSION */
 	/* Complete with available extensions rather than installed ones. */
 	else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 &&
 			 pg_strcasecmp(prev_wd, "EXTENSION") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions);
+		COMPLETE_WITH_QUERY(Query_for_list_of_available_extensions, NULL);
 	/* CREATE EXTENSION <name> */
 	else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "EXTENSION") == 0)
@@ -2291,8 +2277,8 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "EXTENSION") == 0 &&
 			 pg_strcasecmp(prev_wd, "VERSION") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions);
+		COMPLETE_WITH_QUERY(Query_for_list_of_available_extension_versions,
+							prev2_wd);
 	}
 
 	/* CREATE FOREIGN */
@@ -2382,7 +2368,7 @@ psql_completion(const char *text, int start, int end)
 			  pg_strcasecmp(prev4_wd, "INDEX") == 0) &&
 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
 			 pg_strcasecmp(prev_wd, "USING") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
+		COMPLETE_WITH_QUERY(Query_for_list_of_access_methods, NULL);
 	else if (pg_strcasecmp(prev4_wd, "ON") == 0 &&
 			 (!(pg_strcasecmp(prev6_wd, "POLICY") == 0) &&
 			  !(pg_strcasecmp(prev4_wd, "FOR") == 0)) &&
@@ -2473,7 +2459,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev5_wd, "POLICY") == 0 &&
 			 pg_strcasecmp(prev3_wd, "ON") == 0 &&
 			 pg_strcasecmp(prev_wd, "TO") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles, NULL);
 	/* Complete "CREATE POLICY <name> ON <table> USING (" */
 	else if (pg_strcasecmp(prev6_wd, "CREATE") == 0 &&
 			 pg_strcasecmp(prev5_wd, "POLICY") == 0 &&
@@ -2934,7 +2920,7 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
 			 pg_strcasecmp(prev2_wd, "OWNED") == 0 &&
 			 pg_strcasecmp(prev_wd, "BY") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
 			 pg_strcasecmp(prev2_wd, "TEXT") == 0 &&
 			 pg_strcasecmp(prev_wd, "SEARCH") == 0)
@@ -2956,8 +2942,7 @@ psql_completion(const char *text, int start, int end)
 			 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);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_trigger, prev2_wd);
 	}
 	else if (pg_strcasecmp(prev5_wd, "DROP") == 0 &&
 			 pg_strcasecmp(prev4_wd, "TRIGGER") == 0 &&
@@ -2979,14 +2964,14 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "EVENT") == 0 &&
 			 pg_strcasecmp(prev_wd, "TRIGGER") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers, NULL);
 	}
 
 	/* DROP POLICY <name>  */
 	else if (pg_strcasecmp(prev2_wd, "DROP") == 0 &&
 			 pg_strcasecmp(prev_wd, "POLICY") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_policies);
+		COMPLETE_WITH_QUERY(Query_for_list_of_policies, NULL);
 	}
 	/* DROP POLICY <name> ON */
 	else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&
@@ -2999,8 +2984,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "POLICY") == 0 &&
 			 pg_strcasecmp(prev_wd, "ON") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_policy, prev2_wd);
 	}
 
 	/* DROP RULE */
@@ -3013,8 +2997,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "RULE") == 0 &&
 			 pg_strcasecmp(prev_wd, "ON") == 0)
 	{
-		completion_info_charp = prev2_wd;
-		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tables_for_rule, prev2_wd);
 	}
 	else if (pg_strcasecmp(prev5_wd, "DROP") == 0 &&
 			 pg_strcasecmp(prev4_wd, "RULE") == 0 &&
@@ -3029,7 +3012,7 @@ psql_completion(const char *text, int start, int end)
 /* EXECUTE, but not EXECUTE embedded in other commands */
 	else if (pg_strcasecmp(prev_wd, "EXECUTE") == 0 &&
 			 prev2_wd[0] == '\0')
-		COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);
+		COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements, NULL);
 
 /* EXPLAIN */
 
@@ -3103,7 +3086,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "FOREIGN") == 0 &&
 			 pg_strcasecmp(prev2_wd, "DATA") == 0 &&
 			 pg_strcasecmp(prev_wd, "WRAPPER") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_fdws);
+		COMPLETE_WITH_QUERY(Query_for_list_of_fdws, NULL);
 
 /* FOREIGN TABLE */
 	else if (pg_strcasecmp(prev3_wd, "CREATE") != 0 &&
@@ -3114,7 +3097,7 @@ psql_completion(const char *text, int start, int end)
 /* FOREIGN SERVER */
 	else if (pg_strcasecmp(prev2_wd, "FOREIGN") == 0 &&
 			 pg_strcasecmp(prev_wd, "SERVER") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_servers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_servers, NULL);
 
 /* GRANT && REVOKE */
 	/* Complete GRANT/REVOKE with a list of roles and privileges */
@@ -3134,7 +3117,8 @@ psql_completion(const char *text, int start, int end)
 							" UNION SELECT 'TEMPORARY'"
 							" UNION SELECT 'EXECUTE'"
 							" UNION SELECT 'USAGE'"
-							" UNION SELECT 'ALL'");
+							" UNION SELECT 'ALL'",
+							NULL);
 	}
 
 	/*
@@ -3233,21 +3217,21 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev2_wd, "ON") == 0)
 	{
 		if (pg_strcasecmp(prev_wd, "DATABASE") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_databases);
+			COMPLETE_WITH_QUERY(Query_for_list_of_databases, NULL);
 		else if (pg_strcasecmp(prev_wd, "DOMAIN") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains, NULL);
 		else if (pg_strcasecmp(prev_wd, "FUNCTION") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 		else if (pg_strcasecmp(prev_wd, "LANGUAGE") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_languages);
+			COMPLETE_WITH_QUERY(Query_for_list_of_languages, NULL);
 		else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+			COMPLETE_WITH_QUERY(Query_for_list_of_schemas, NULL);
 		else if (pg_strcasecmp(prev_wd, "SEQUENCE") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL);
 		else if (pg_strcasecmp(prev_wd, "TABLE") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf, NULL);
 		else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
+			COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces, NULL);
 		else if (pg_strcasecmp(prev_wd, "TYPE") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
 		else if (pg_strcasecmp(prev4_wd, "GRANT") == 0)
@@ -3313,7 +3297,7 @@ psql_completion(const char *text, int start, int end)
 			   pg_strcasecmp(prev6_wd, "REVOKE") == 0 ||
 			   pg_strcasecmp(prev5_wd, "REVOKE") == 0) &&
 			  pg_strcasecmp(prev_wd, "FROM") == 0))
-		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles, NULL);
 
 	/* Complete "GRANT/REVOKE * ON * *" with TO/FROM */
 	else if (pg_strcasecmp(prev5_wd, "GRANT") == 0 &&
@@ -3331,12 +3315,12 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev3_wd, "GRANT") == 0 &&
 			 pg_strcasecmp(prev_wd, "TO") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles, NULL);
 	}
 	else if (pg_strcasecmp(prev3_wd, "REVOKE") == 0 &&
 			 pg_strcasecmp(prev_wd, "FROM") == 0)
 	{
-		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_grant_roles, NULL);
 	}
 
 /* GROUP BY */
@@ -3433,7 +3417,7 @@ psql_completion(const char *text, int start, int end)
 
 /* NOTIFY */
 	else if (pg_strcasecmp(prev_wd, "NOTIFY") == 0)
-		COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'");
+		COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s'", NULL);
 
 /* OPTIONS */
 	else if (pg_strcasecmp(prev_wd, "OPTIONS") == 0)
@@ -3442,7 +3426,7 @@ psql_completion(const char *text, int start, int end)
 /* OWNER TO  - complete with available roles */
 	else if (pg_strcasecmp(prev2_wd, "OWNER") == 0 &&
 			 pg_strcasecmp(prev_wd, "TO") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 
 /* ORDER BY */
 	else if (pg_strcasecmp(prev3_wd, "FROM") == 0 &&
@@ -3477,7 +3461,7 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev_wd, "BY") == 0 &&
 			 pg_strcasecmp(prev2_wd, "OWNED") == 0 &&
 			 pg_strcasecmp(prev3_wd, "REASSIGN") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	else if (pg_strcasecmp(prev2_wd, "BY") == 0 &&
 			 pg_strcasecmp(prev3_wd, "OWNED") == 0 &&
 			 pg_strcasecmp(prev4_wd, "REASSIGN") == 0)
@@ -3486,7 +3470,7 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev3_wd, "BY") == 0 &&
 			 pg_strcasecmp(prev4_wd, "OWNED") == 0 &&
 			 pg_strcasecmp(prev5_wd, "REASSIGN") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 
 /* REFRESH MATERIALIZED VIEW */
 	else if (pg_strcasecmp(prev_wd, "REFRESH") == 0)
@@ -3551,10 +3535,10 @@ psql_completion(const char *text, int start, int end)
 		else if (pg_strcasecmp(prev_wd, "INDEX") == 0)
 			COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
 		else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+			COMPLETE_WITH_QUERY(Query_for_list_of_schemas, NULL);
 		else if (pg_strcasecmp(prev_wd, "SYSTEM") == 0 ||
 				 pg_strcasecmp(prev_wd, "DATABASE") == 0)
-			COMPLETE_WITH_QUERY(Query_for_list_of_databases);
+			COMPLETE_WITH_QUERY(Query_for_list_of_databases, NULL);
 	}
 
 /* SECURITY LABEL */
@@ -3600,9 +3584,9 @@ psql_completion(const char *text, int start, int end)
 	else if ((pg_strcasecmp(prev_wd, "SET") == 0 &&
 			  pg_strcasecmp(prev3_wd, "UPDATE") != 0) ||
 			 pg_strcasecmp(prev_wd, "RESET") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_set_vars);
+		COMPLETE_WITH_QUERY(Query_for_list_of_set_vars, NULL);
 	else if (pg_strcasecmp(prev_wd, "SHOW") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_show_vars);
+		COMPLETE_WITH_QUERY(Query_for_list_of_show_vars, NULL);
 	/* Complete "SET TRANSACTION" */
 	else if ((pg_strcasecmp(prev2_wd, "SET") == 0 &&
 			  pg_strcasecmp(prev_wd, "TRANSACTION") == 0)
@@ -3693,7 +3677,7 @@ psql_completion(const char *text, int start, int end)
 	/* Complete SET ROLE */
 	else if (pg_strcasecmp(prev2_wd, "SET") == 0 &&
 			 pg_strcasecmp(prev_wd, "ROLE") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	/* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */
 	else if (pg_strcasecmp(prev2_wd, "SET") == 0 &&
 			 pg_strcasecmp(prev_wd, "SESSION") == 0)
@@ -3707,7 +3691,8 @@ psql_completion(const char *text, int start, int end)
 	else if (pg_strcasecmp(prev3_wd, "SET") == 0
 			 && pg_strcasecmp(prev2_wd, "SESSION") == 0
 			 && pg_strcasecmp(prev_wd, "AUTHORIZATION") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles " UNION SELECT 'DEFAULT'");
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles " UNION SELECT 'DEFAULT'",
+							NULL);
 	/* Complete RESET SESSION with AUTHORIZATION */
 	else if (pg_strcasecmp(prev2_wd, "RESET") == 0 &&
 			 pg_strcasecmp(prev_wd, "SESSION") == 0)
@@ -3741,7 +3726,8 @@ psql_completion(const char *text, int start, int end)
 			COMPLETE_WITH_QUERY(Query_for_list_of_schemas
 								" AND nspname not like 'pg\\_toast%%' "
 								" AND nspname not like 'pg\\_temp%%' "
-								" UNION SELECT 'DEFAULT' ");
+								" UNION SELECT 'DEFAULT' ",
+								NULL);
 		}
 		else
 		{
@@ -3754,7 +3740,7 @@ psql_completion(const char *text, int start, int end)
 				char		querybuf[1024];
 
 				snprintf(querybuf, 1024, Query_for_enum, prev2_wd);
-				COMPLETE_WITH_QUERY(querybuf);
+				COMPLETE_WITH_QUERY(querybuf, NULL);
 			}
 			else if (guctype && strcmp(guctype, "bool") == 0)
 			{
@@ -3787,7 +3773,7 @@ psql_completion(const char *text, int start, int end)
 
 /* TABLESAMPLE */
 	else if (pg_strcasecmp(prev_wd, "TABLESAMPLE") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tablesample_methods, NULL);
 
 	else if (pg_strcasecmp(prev2_wd, "TABLESAMPLE") == 0)
 		COMPLETE_WITH_CONST("(");
@@ -3798,7 +3784,7 @@ psql_completion(const char *text, int start, int end)
 
 /* UNLISTEN */
 	else if (pg_strcasecmp(prev_wd, "UNLISTEN") == 0)
-		COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s' UNION SELECT '*'");
+		COMPLETE_WITH_QUERY("SELECT pg_catalog.quote_ident(channel) FROM pg_catalog.pg_listening_channels() AS channel WHERE substring(pg_catalog.quote_ident(channel),1,%d)='%s' UNION SELECT '*'", NULL);
 
 /* UPDATE */
 	/* If prev. word is UPDATE suggest a list of tables */
@@ -3835,13 +3821,13 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles
 							" UNION SELECT 'CURRENT_USER'"
 							" UNION SELECT 'PUBLIC'"
-							" UNION SELECT 'USER'");
+							" UNION SELECT 'USER'", NULL);
 	else if ((pg_strcasecmp(prev4_wd, "ALTER") == 0 ||
 			  pg_strcasecmp(prev4_wd, "DROP") == 0) &&
 			 pg_strcasecmp(prev3_wd, "USER") == 0 &&
 			 pg_strcasecmp(prev2_wd, "MAPPING") == 0 &&
 			 pg_strcasecmp(prev_wd, "FOR") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
+		COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings, NULL);
 	else if ((pg_strcasecmp(prev5_wd, "CREATE") == 0 ||
 			  pg_strcasecmp(prev5_wd, "ALTER") == 0 ||
 			  pg_strcasecmp(prev5_wd, "DROP") == 0) &&
@@ -3935,44 +3921,44 @@ psql_completion(const char *text, int start, int end)
 	else if (strcmp(prev_wd, "\\connect") == 0 || strcmp(prev_wd, "\\c") == 0)
 	{
 		if (!recognized_connection_string(text))
-			COMPLETE_WITH_QUERY(Query_for_list_of_databases);
+			COMPLETE_WITH_QUERY(Query_for_list_of_databases, NULL);
 	}
 	else if (strcmp(prev2_wd, "\\connect") == 0 || strcmp(prev2_wd, "\\c") == 0)
 	{
 		if (!recognized_connection_string(prev_wd))
-			COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+			COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	}
 	else if (strncmp(prev_wd, "\\da", strlen("\\da")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);
 	else if (strncmp(prev_wd, "\\db", strlen("\\db")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
+		COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces, NULL);
 	else if (strncmp(prev_wd, "\\dD", strlen("\\dD")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains, NULL);
 	else if (strncmp(prev_wd, "\\des", strlen("\\des")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_servers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_servers, NULL);
 	else if (strncmp(prev_wd, "\\deu", strlen("\\deu")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings);
+		COMPLETE_WITH_QUERY(Query_for_list_of_user_mappings, NULL);
 	else if (strncmp(prev_wd, "\\dew", strlen("\\dew")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_fdws);
+		COMPLETE_WITH_QUERY(Query_for_list_of_fdws, NULL);
 
 	else if (strncmp(prev_wd, "\\df", strlen("\\df")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strncmp(prev_wd, "\\dFd", strlen("\\dFd")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_ts_dictionaries);
+		COMPLETE_WITH_QUERY(Query_for_list_of_ts_dictionaries, NULL);
 	else if (strncmp(prev_wd, "\\dFp", strlen("\\dFp")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_ts_parsers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_ts_parsers, NULL);
 	else if (strncmp(prev_wd, "\\dFt", strlen("\\dFt")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_ts_templates);
+		COMPLETE_WITH_QUERY(Query_for_list_of_ts_templates, NULL);
 	/* must be at end of \dF */
 	else if (strncmp(prev_wd, "\\dF", strlen("\\dF")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_ts_configurations);
+		COMPLETE_WITH_QUERY(Query_for_list_of_ts_configurations, NULL);
 
 	else if (strncmp(prev_wd, "\\di", strlen("\\di")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
 	else if (strncmp(prev_wd, "\\dL", strlen("\\dL")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_languages);
+		COMPLETE_WITH_QUERY(Query_for_list_of_languages, NULL);
 	else if (strncmp(prev_wd, "\\dn", strlen("\\dn")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
+		COMPLETE_WITH_QUERY(Query_for_list_of_schemas, NULL);
 	else if (strncmp(prev_wd, "\\dp", strlen("\\dp")) == 0
 			 || strncmp(prev_wd, "\\z", strlen("\\z")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tsvmf, NULL);
@@ -3984,17 +3970,17 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
 	else if (strncmp(prev_wd, "\\du", strlen("\\du")) == 0
 			 || (strncmp(prev_wd, "\\dg", strlen("\\dg")) == 0))
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	else if (strncmp(prev_wd, "\\dv", strlen("\\dv")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
 	else if (strncmp(prev_wd, "\\dx", strlen("\\dx")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_extensions);
+		COMPLETE_WITH_QUERY(Query_for_list_of_extensions, NULL);
 	else if (strncmp(prev_wd, "\\dm", strlen("\\dm")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_matviews, NULL);
 	else if (strncmp(prev_wd, "\\dE", strlen("\\dE")) == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_foreign_tables, NULL);
 	else if (strncmp(prev_wd, "\\dy", strlen("\\dy")) == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers);
+		COMPLETE_WITH_QUERY(Query_for_list_of_event_triggers, NULL);
 
 	/* must be at end of \d list */
 	else if (strncmp(prev_wd, "\\d", strlen("\\d")) == 0)
@@ -4006,11 +3992,11 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
 
 	else if (strcmp(prev_wd, "\\encoding") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_encodings);
+		COMPLETE_WITH_QUERY(Query_for_list_of_encodings, NULL);
 	else if (strcmp(prev_wd, "\\h") == 0 || strcmp(prev_wd, "\\help") == 0)
 		COMPLETE_WITH_LIST(sql_commands);
 	else if (strcmp(prev_wd, "\\password") == 0)
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY(Query_for_list_of_roles, NULL);
 	else if (strcmp(prev_wd, "\\pset") == 0)
 	{
 		static const char *const my_list[] =
@@ -4156,7 +4142,7 @@ psql_completion(const char *text, int start, int end)
 			if (pg_strcasecmp(prev_wd, words_after_create[i].name) == 0)
 			{
 				if (words_after_create[i].query)
-					COMPLETE_WITH_QUERY(words_after_create[i].query);
+					COMPLETE_WITH_QUERY(words_after_create[i].query, NULL);
 				else if (words_after_create[i].squery)
 					COMPLETE_WITH_SCHEMA_QUERY(*words_after_create[i].squery,
 											   NULL);
-- 
1.8.3.1

