Re: Improve the HINT message of the ALTER command for postgres_fdw

2021-10-12 Thread bt21masumurak

Hi
Thank you for your comments.

It seems like the change proposed for postgres_fdw_validator is 
similar to what
file_fdw is doing in file_fdw_validator.  I think we also need to do 
the same

change in dblink_fdw_validator and postgresql_fdw_validator as well.


Agreed.


While on this, it's better to add test cases for the error message
"There are no valid options in this context." for all the three fdws
i.e. file_fdw, postgres_fdw and dblink_fdw may be in their respective
contrib modules test files, and for postgresql_fdw_validator in
src/test/regress/sql/foreign_data.sql.


+1.


I made new patch based on those comments.

Regards,
Kosei Masumura


2021-10-08 17:13 に Daniel Gustafsson さんは書きました:
On 8 Oct 2021, at 09:38, Bharath Rupireddy 
 wrote:


On Fri, Oct 8, 2021 at 12:48 PM bt21masumurak
 wrote:


Hi

When 'ALTER FOREIGN DATA WRAPPER OPTIONS' is executed against
postgres_fdw, the HINT message is printed as shown below, even though
there are no valid options in this context.

=# ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (format 'csv');
ERROR: invalid option "format"
HINT: Valid options in this context are:

I made a patch for this problem.


Good catch.


+1

It seems like the change proposed for postgres_fdw_validator is 
similar to what
file_fdw is doing in file_fdw_validator.  I think we also need to do 
the same

change in dblink_fdw_validator and postgresql_fdw_validator as well.


Agreed.


While on this, it's better to add test cases for the error message
"There are no valid options in this context." for all the three fdws
i.e. file_fdw, postgres_fdw and dblink_fdw may be in their respective
contrib modules test files, and for postgresql_fdw_validator in
src/test/regress/sql/foreign_data.sql.


+1.

--
Daniel Gustafsson   https://vmware.com/
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 3a0beaa88e..c8b0b4ff3f 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -2054,8 +2054,10 @@ dblink_fdw_validator(PG_FUNCTION_ARGS)
 			ereport(ERROR,
 	(errcode(ERRCODE_FDW_OPTION_NAME_NOT_FOUND),
 	 errmsg("invalid option \"%s\"", def->defname),
-	 errhint("Valid options in this context are: %s",
-			 buf.data)));
+	 buf.len > 0
+	 ? errhint("Valid options in this context are: %s",
+			   buf.data)
+	 : errhint("There are no valid options in this context.")));
 		}
 	}
 
diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out
index 6516d4f131..48a4d5ea99 100644
--- a/contrib/dblink/expected/dblink.out
+++ b/contrib/dblink/expected/dblink.out
@@ -1,4 +1,8 @@
 CREATE EXTENSION dblink;
+-- HINT test
+ALTER FOREIGN DATA WRAPPER dblink_fdw OPTIONS (format 'csv');
+ERROR:  invalid option "format"
+HINT:  There are no valid options in this context.
 -- want context for notices
 \set SHOW_CONTEXT always
 CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
diff --git a/contrib/dblink/sql/dblink.sql b/contrib/dblink/sql/dblink.sql
index 3e96b98571..fa0a307c73 100644
--- a/contrib/dblink/sql/dblink.sql
+++ b/contrib/dblink/sql/dblink.sql
@@ -1,5 +1,6 @@
 CREATE EXTENSION dblink;
-
+-- HINT test
+ALTER FOREIGN DATA WRAPPER dblink_fdw OPTIONS (format 'csv');
 -- want context for notices
 \set SHOW_CONTEXT always
 
diff --git a/contrib/file_fdw/input/file_fdw.source b/contrib/file_fdw/input/file_fdw.source
index 45b728eeb3..d634f70ebf 100644
--- a/contrib/file_fdw/input/file_fdw.source
+++ b/contrib/file_fdw/input/file_fdw.source
@@ -14,6 +14,9 @@ CREATE ROLE regress_no_priv_user LOGIN; -- has priv but no user
 -- Install file_fdw
 CREATE EXTENSION file_fdw;
 
+--HINT test
+ALTER FOREIGN DATA WRAPPER file_fdw OPTIONS (format 'csv');
+
 -- regress_file_fdw_superuser owns fdw-related objects
 SET ROLE regress_file_fdw_superuser;
 CREATE SERVER file_server FOREIGN DATA WRAPPER file_fdw;
diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source
index 52b4d5f1df..7bcd8a1e9b 100644
--- a/contrib/file_fdw/output/file_fdw.source
+++ b/contrib/file_fdw/output/file_fdw.source
@@ -10,6 +10,10 @@ CREATE ROLE regress_file_fdw_user LOGIN;-- has priv and user map
 CREATE ROLE regress_no_priv_user LOGIN; -- has priv but no user mapping
 -- Install file_fdw
 CREATE EXTENSION file_fdw;
+--HINT test
+ALTER FOREIGN DATA WRAPPER file_fdw OPTIONS (format 'csv');
+ERROR:  invalid option "format"
+HINT:  There are no valid options in this context.
 -- regress_file_fdw_superuser owns fdw-related objects
 SET ROLE regress_file_fdw_superuser;
 CREATE SERVER file_server FOREIGN DATA WRAPPER file_fdw;
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index

Re: Improved tab completion for PostgreSQL parameters in enums

2021-10-13 Thread bt21masumurak

Thank you for comments.


I do not think this is an improvement.  It will result in omitting
quotes in some cases where they're not optional.  Try it with a
value such as "all", for example.



This would break the completion of enum entries that require quotes to
work properly for some of their values, like
default_transaction_isolation.


I understand these comments, and the proposal was withdrawn.

Regards,
Kosei Masumura

2021-10-06 23:34 に Tom Lane さんは書きました:

bt21masumurak  writes:

If you do tab completion in a situation like A, you will see ["on"]
instead of [on].



A : "ALTER SYSTEM SET wal_compression TO "



I made a patch for this problem.


I do not think this is an improvement.  It will result in omitting
quotes in some cases where they're not optional.  Try it with a
value such as "all", for example.

regards, tom lane





Improved tab completion for PostgreSQL parameters in enums

2021-10-05 Thread bt21masumurak

Hi

If you do tab completion in a situation like A, you will see ["on"] 
instead of [on].


A : "ALTER SYSTEM SET wal_compression TO "

I made a patch for this problem.

regards,
Kosei Masumuradiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 4155d81252..86087e790b 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -969,7 +969,7 @@ Query_for_index_of_table \
 
 #define Query_for_enum \
 " SELECT name FROM ( "\
-"   SELECT pg_catalog.quote_ident(pg_catalog.unnest(enumvals)) AS name "\
+"   SELECT pg_catalog.unnest(enumvals) AS name "\
 " FROM pg_catalog.pg_settings "\
 "WHERE pg_catalog.lower(name)=pg_catalog.lower('%s') "\
 "UNION ALL " \


Improve the HINT message of the ALTER command for postgres_fdw

2021-10-08 Thread bt21masumurak

Hi

When 'ALTER FOREIGN DATA WRAPPER OPTIONS' is executed against 
postgres_fdw, the HINT message is printed as shown below, even though 
there are no valid options in this context.


=# ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (format 'csv');
ERROR: invalid option "format"
HINT: Valid options in this context are:

I made a patch for this problem.


regards,
Kosei Masumuradiff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 5bb1af4084..19edf98360 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -107,8 +107,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 			ereport(ERROR,
 	(errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
 	 errmsg("invalid option \"%s\"", def->defname),
-	 errhint("Valid options in this context are: %s",
-			 buf.data)));
+	 buf.len > 0
+ ? errhint("Valid options in this context are: %s",
+ buf.data)
+ : errhint("There are no valid options in this context.")));
 		}
 
 		/*