Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5fedf74

Browse files
committed
Improve HINT message that FDW reports when there are no valid options.
The foreign data wrapper's validator function provides a HINT message with list of valid options for the object specified in CREATE or ALTER command, when the option given in the command is invalid. Previously postgresql_fdw_validator() and the validator functions for postgres_fdw and dblink_fdw worked in that way even there were no valid options in the object, which could lead to the HINT message with empty list (because there were no valid options). For example, ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (format 'csv') reported the following ERROR and HINT messages. This behavior was confusing. ERROR: invalid option "format" HINT: Valid options in this context are: There is no such issue in file_fdw. The validator function for file_fdw reports the HINT message "There are no valid options in this context." instead in that case. This commit improves postgresql_fdw_validator() and the validator functions for postgres_fdw and dblink_fdw so that they do likewise. For example, this change causes the above ALTER FOREIGN DATA WRAPPER command to report the following messages. ERROR: invalid option "nonexistent" HINT: There are no valid options in this context. Author: Kosei Masumura Reviewed-by: Bharath Rupireddy, Fujii Masao Discussion: https://postgr.es/m/557d06cebe19081bfcc83ee2affc98d3@oss.nttdata.com
1 parent e63ce9e commit 5fedf74

File tree

9 files changed

+33
-8
lines changed

9 files changed

+33
-8
lines changed

contrib/dblink/dblink.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,10 @@ dblink_fdw_validator(PG_FUNCTION_ARGS)
20542054
ereport(ERROR,
20552055
(errcode(ERRCODE_FDW_OPTION_NAME_NOT_FOUND),
20562056
errmsg("invalid option \"%s\"", def->defname),
2057-
errhint("Valid options in this context are: %s",
2058-
buf.data)));
2057+
buf.len > 0
2058+
? errhint("Valid options in this context are: %s",
2059+
buf.data)
2060+
: errhint("There are no valid options in this context.")));
20592061
}
20602062
}
20612063

contrib/dblink/expected/dblink.out

+4
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ REVOKE EXECUTE ON FUNCTION dblink_connect_u(text, text) FROM regress_dblink_user
917917
DROP USER regress_dblink_user;
918918
DROP USER MAPPING FOR public SERVER fdtest;
919919
DROP SERVER fdtest;
920+
-- should fail
921+
ALTER FOREIGN DATA WRAPPER dblink_fdw OPTIONS (nonexistent 'fdw');
922+
ERROR: invalid option "nonexistent"
923+
HINT: There are no valid options in this context.
920924
-- test asynchronous notifications
921925
SELECT dblink_connect(connection_parameters());
922926
dblink_connect

contrib/dblink/sql/dblink.sql

+3
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ DROP USER regress_dblink_user;
463463
DROP USER MAPPING FOR public SERVER fdtest;
464464
DROP SERVER fdtest;
465465

466+
-- should fail
467+
ALTER FOREIGN DATA WRAPPER dblink_fdw OPTIONS (nonexistent 'fdw');
468+
466469
-- test asynchronous notifications
467470
SELECT dblink_connect(connection_parameters());
468471

contrib/postgres_fdw/expected/postgres_fdw.out

+5-1
Original file line numberDiff line numberDiff line change
@@ -10746,7 +10746,7 @@ DROP TABLE join_tbl;
1074610746
ALTER SERVER loopback OPTIONS (DROP async_capable);
1074710747
ALTER SERVER loopback2 OPTIONS (DROP async_capable);
1074810748
-- ===================================================================
10749-
-- test invalid server and foreign table options
10749+
-- test invalid server, foreign table and foreign data wrapper options
1075010750
-- ===================================================================
1075110751
-- Invalid fdw_startup_cost option
1075210752
CREATE SERVER inv_scst FOREIGN DATA WRAPPER postgres_fdw
@@ -10764,3 +10764,7 @@ ERROR: invalid value for integer option "fetch_size": 100$%$#$#
1076410764
CREATE FOREIGN TABLE inv_bsz (c1 int )
1076510765
SERVER loopback OPTIONS (batch_size '100$%$#$#');
1076610766
ERROR: invalid value for integer option "batch_size": 100$%$#$#
10767+
-- No option is allowed to be specified at foreign data wrapper level
10768+
ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (nonexistent 'fdw');
10769+
ERROR: invalid option "nonexistent"
10770+
HINT: There are no valid options in this context.

contrib/postgres_fdw/option.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
107107
ereport(ERROR,
108108
(errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
109109
errmsg("invalid option \"%s\"", def->defname),
110-
errhint("Valid options in this context are: %s",
111-
buf.data)));
110+
buf.len > 0
111+
? errhint("Valid options in this context are: %s",
112+
buf.data)
113+
: errhint("There are no valid options in this context.")));
112114
}
113115

114116
/*

contrib/postgres_fdw/sql/postgres_fdw.sql

+4-1
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ ALTER SERVER loopback OPTIONS (DROP async_capable);
34093409
ALTER SERVER loopback2 OPTIONS (DROP async_capable);
34103410

34113411
-- ===================================================================
3412-
-- test invalid server and foreign table options
3412+
-- test invalid server, foreign table and foreign data wrapper options
34133413
-- ===================================================================
34143414
-- Invalid fdw_startup_cost option
34153415
CREATE SERVER inv_scst FOREIGN DATA WRAPPER postgres_fdw
@@ -3423,3 +3423,6 @@ CREATE FOREIGN TABLE inv_fsz (c1 int )
34233423
-- Invalid batch_size option
34243424
CREATE FOREIGN TABLE inv_bsz (c1 int )
34253425
SERVER loopback OPTIONS (batch_size '100$%$#$#');
3426+
3427+
-- No option is allowed to be specified at foreign data wrapper level
3428+
ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (nonexistent 'fdw');

src/backend/foreign/foreign.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,10 @@ postgresql_fdw_validator(PG_FUNCTION_ARGS)
670670
ereport(ERROR,
671671
(errcode(ERRCODE_SYNTAX_ERROR),
672672
errmsg("invalid option \"%s\"", def->defname),
673-
errhint("Valid options in this context are: %s",
674-
buf.data)));
673+
buf.len > 0
674+
? errhint("Valid options in this context are: %s",
675+
buf.data)
676+
: errhint("There are no valid options in this context.")));
675677

676678
PG_RETURN_BOOL(false);
677679
}

src/test/regress/expected/foreign_data.out

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ LINE 1: ...GN DATA WRAPPER test_fdw HANDLER test_fdw_handler HANDLER in...
100100
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler;
101101
DROP FOREIGN DATA WRAPPER test_fdw;
102102
-- ALTER FOREIGN DATA WRAPPER
103+
ALTER FOREIGN DATA WRAPPER foo OPTIONS (nonexistent 'fdw'); -- ERROR
104+
ERROR: invalid option "nonexistent"
105+
HINT: There are no valid options in this context.
103106
ALTER FOREIGN DATA WRAPPER foo; -- ERROR
104107
ERROR: syntax error at or near ";"
105108
LINE 1: ALTER FOREIGN DATA WRAPPER foo;

src/test/regress/sql/foreign_data.sql

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler;
5959
DROP FOREIGN DATA WRAPPER test_fdw;
6060

6161
-- ALTER FOREIGN DATA WRAPPER
62+
ALTER FOREIGN DATA WRAPPER foo OPTIONS (nonexistent 'fdw'); -- ERROR
63+
6264
ALTER FOREIGN DATA WRAPPER foo; -- ERROR
6365
ALTER FOREIGN DATA WRAPPER foo VALIDATOR bar; -- ERROR
6466
ALTER FOREIGN DATA WRAPPER foo NO VALIDATOR;

0 commit comments

Comments
 (0)