agora inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH v3 2/2] regress - Add missing targets in ATWrongRelkindError
7+ messages / 2 participants
[nested] [flat]

* [PATCH v3 2/2] regress - Add missing targets in ATWrongRelkindError
@ 2021-07-09 11:40  Kyotaro Horiguchi <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Kyotaro Horiguchi @ 2021-07-09 11:40 UTC (permalink / raw)

---
 src/test/regress/expected/alter_table.out  | 4 ++++
 src/test/regress/expected/foreign_data.out | 4 +++-
 src/test/regress/sql/alter_table.sql       | 4 ++++
 src/test/regress/sql/foreign_data.sql      | 3 ++-
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 8d91e2d6c8..5f6d4ed7c3 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -6,6 +6,7 @@ SET client_min_messages TO 'warning';
 DROP ROLE IF EXISTS regress_alter_table_user1;
 RESET client_min_messages;
 CREATE USER regress_alter_table_user1;
+CREATE VIEW at_v1 AS SELECT 1 as a;
 --
 -- add attribute
 --
@@ -3948,6 +3949,9 @@ ERROR:  remainder for hash partition must be less than modulus
 ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, REMAINDER 2);
 ERROR:  every hash partition modulus must be a factor of the next larger modulus
 DROP TABLE fail_part;
+-- check that attach partition correctly complains for the object of a wrong type
+ALTER TABLE at_v1 ATTACH PARTITION dummy default; -- ERROR
+ERROR:  "at_v1" is not a partitioned table or index
 --
 -- DETACH PARTITION
 --
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index b9e25820bc..ffa9287967 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -877,8 +877,10 @@ ERROR:  column "no_column" of relation "ft1" does not exist
 ALTER FOREIGN TABLE ft1 DROP COLUMN IF EXISTS no_column;
 NOTICE:  column "no_column" of relation "ft1" does not exist, skipping
 ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
+ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR (wrong object type)
+ERROR:  "ft1" is not a table, materialized view, index, or partitioned index
 ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema;
-ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR
+ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR (not found)
 ERROR:  relation "ft1" does not exist
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1;
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index cd925ea8ce..a92cea7f87 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -8,6 +8,7 @@ DROP ROLE IF EXISTS regress_alter_table_user1;
 RESET client_min_messages;
 
 CREATE USER regress_alter_table_user1;
+CREATE VIEW at_v1 AS SELECT 1 as a;
 
 --
 -- add attribute
@@ -2593,6 +2594,9 @@ ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 8, R
 ALTER TABLE hash_parted ATTACH PARTITION fail_part FOR VALUES WITH (MODULUS 3, REMAINDER 2);
 DROP TABLE fail_part;
 
+-- check that attach partition correctly complains for the object of a wrong type
+ALTER TABLE at_v1 ATTACH PARTITION dummy default; -- ERROR
+
 --
 -- DETACH PARTITION
 --
diff --git a/src/test/regress/sql/foreign_data.sql b/src/test/regress/sql/foreign_data.sql
index 73f9f621d8..e96aef5396 100644
--- a/src/test/regress/sql/foreign_data.sql
+++ b/src/test/regress/sql/foreign_data.sql
@@ -406,8 +406,9 @@ ALTER FOREIGN TABLE ft1 OPTIONS (DROP delimiter, SET quote '~', ADD escape '@');
 ALTER FOREIGN TABLE ft1 DROP COLUMN no_column;                  -- ERROR
 ALTER FOREIGN TABLE ft1 DROP COLUMN IF EXISTS no_column;
 ALTER FOREIGN TABLE ft1 DROP COLUMN c9;
+ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR (wrong object type)
 ALTER FOREIGN TABLE ft1 SET SCHEMA foreign_schema;
-ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR
+ALTER FOREIGN TABLE ft1 SET TABLESPACE ts;                      -- ERROR (not found)
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1;
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
 \d foreign_schema.foreign_table_1
-- 
2.27.0


----Next_Part(Fri_Jul__9_21_00_31_2021_633)----





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH v4 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 37524364290..1b4855edab6 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2189,7 +2199,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2200,7 +2210,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3308,17 +3318,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5417,9 +5419,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5519,11 +5521,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Thu__17_Jul_2025_10_57_36_+0900_dz7Bjsed2AEN=CJ+--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH v5 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 37524364290..1b4855edab6 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2189,7 +2199,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2200,7 +2210,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3308,17 +3318,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5417,9 +5419,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5519,11 +5521,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Fri__18_Jul_2025_16_49_28_+0900_ThDewLMcz6Ys6Zwo--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH v6 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 6b20a4404b2..6176741d20b 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(generator) \
+	matches = rl_completion_matches(text, generator)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2182,7 +2192,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2192,7 +2202,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2203,7 +2213,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3316,17 +3326,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5427,9 +5429,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5529,11 +5531,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Thu__18_Sep_2025_12_05_06_+0900_I2R/usu+NR/K2VUG--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index ec65ab79fec..8a85a285281 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2158,7 +2168,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2168,7 +2178,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3264,17 +3274,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5347,9 +5349,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5449,11 +5451,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Thu__5_Jun_2025_10_08_35_+0900_P.h1uSLN4yp_7Ild--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH v2 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index ec65ab79fec..8a85a285281 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2158,7 +2168,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2168,7 +2178,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3264,17 +3274,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5347,9 +5349,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5449,11 +5451,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Thu__5_Jun_2025_16_52_00_+0900_d_5fKAN_xESbgyqx--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* [PATCH v3 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches()
@ 2025-06-05 00:38  Yugo Nagata <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Yugo Nagata @ 2025-06-05 00:38 UTC (permalink / raw)

Most tab completions in match_previous_words() use COMPLETE_WITH* macros,
which wrap rl_completion_matches(). However, some direct calls to
rl_completion_matches() still remained.

This commit replaces the remaining direct calls with the new macro,
COMPLETE_WITH_FILES or COMPLETE_WITH_GENERATOR, for improved consistency and
readability.
---
 src/bin/psql/tab-complete.in.c | 38 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 2c0b4f28c14..2716554aa0b 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -443,6 +443,16 @@ do { \
 	matches = rl_completion_matches(text, complete_from_schema_query); \
 } while (0)
 
+#define COMPLETE_WITH_FILES(escape, force_quote) \
+do { \
+	completion_charp = escape; \
+	completion_force_quote = force_quote; \
+	matches = rl_completion_matches(text, complete_from_files); \
+} while (0)
+
+#define COMPLETE_WITH_GENERATOR(function) \
+	matches = rl_completion_matches(text, function)
+
 /*
  * Assembly instructions for schema queries
  *
@@ -2158,7 +2168,7 @@ match_previous_words(int pattern_id,
 			/* for INDEX and TABLE/SEQUENCE, respectively */
 						  "UNIQUE", "UNLOGGED");
 		else
-			matches = rl_completion_matches(text, create_command_generator);
+			COMPLETE_WITH_GENERATOR(create_command_generator);
 	}
 	/* complete with something you can create or replace */
 	else if (TailMatches("CREATE", "OR", "REPLACE"))
@@ -2168,7 +2178,7 @@ match_previous_words(int pattern_id,
 /* DROP, but not DROP embedded in other commands */
 	/* complete with something you can drop */
 	else if (Matches("DROP"))
-		matches = rl_completion_matches(text, drop_command_generator);
+		COMPLETE_WITH_GENERATOR(drop_command_generator);
 
 /* ALTER */
 
@@ -2179,7 +2189,7 @@ match_previous_words(int pattern_id,
 
 	/* ALTER something */
 	else if (Matches("ALTER"))
-		matches = rl_completion_matches(text, alter_command_generator);
+		COMPLETE_WITH_GENERATOR(alter_command_generator);
 	/* ALTER TABLE,INDEX,MATERIALIZED VIEW ALL IN TABLESPACE xxx */
 	else if (TailMatches("ALL", "IN", "TABLESPACE", MatchAny))
 		COMPLETE_WITH("SET TABLESPACE", "OWNED BY");
@@ -3264,17 +3274,9 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("FROM", "TO");
 	/* Complete COPY <sth> FROM|TO with filename */
 	else if (Matches("COPY", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = true;	/* COPY requires quoted filename */
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", true);	/* COPY requires quoted filename */
 	else if (Matches("\\copy", MatchAny, "FROM|TO"))
-	{
-		completion_charp = "";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("", false);
 
 	/* Complete COPY <sth> TO <sth> */
 	else if (Matches("COPY|\\copy", MatchAny, "TO", MatchAny))
@@ -5348,9 +5350,9 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\h|\\help", MatchAny))
 	{
 		if (TailMatches("DROP"))
-			matches = rl_completion_matches(text, drop_command_generator);
+			COMPLETE_WITH_GENERATOR(drop_command_generator);
 		else if (TailMatches("ALTER"))
-			matches = rl_completion_matches(text, alter_command_generator);
+			COMPLETE_WITH_GENERATOR(alter_command_generator);
 
 		/*
 		 * CREATE is recognized by tail match elsewhere, so doesn't need to be
@@ -5450,11 +5452,7 @@ match_previous_words(int pattern_id,
 	else if (TailMatchesCS("\\cd|\\e|\\edit|\\g|\\gx|\\i|\\include|"
 						   "\\ir|\\include_relative|\\o|\\out|"
 						   "\\s|\\w|\\write|\\lo_import"))
-	{
-		completion_charp = "\\";
-		completion_force_quote = false;
-		matches = rl_completion_matches(text, complete_from_files);
-	}
+		COMPLETE_WITH_FILES("\\", false);
 
 	/* gen_tabcomplete.pl ends special processing here */
 	/* END GEN_TABCOMPLETE */
-- 
2.43.0


--Multipart=_Tue__17_Jun_2025_00_08_32_+0900_g9awdn.2U/+M5mrO--





^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2025-06-05 00:38 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 11:40 [PATCH v3 2/2] regress - Add missing targets in ATWrongRelkindError Kyotaro Horiguchi <[email protected]>
2025-06-05 00:38 [PATCH v3 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>
2025-06-05 00:38 [PATCH v4 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>
2025-06-05 00:38 [PATCH v5 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>
2025-06-05 00:38 [PATCH v6 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>
2025-06-05 00:38 [PATCH 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>
2025-06-05 00:38 [PATCH v2 1/3] Refactor match_previous_words() to remove direct use of rl_completion_matches() Yugo Nagata <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox