From 45790fcd4e94704298734c56bc96bcbd1353a6cb Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Thu, 5 Nov 2026 22:56:51 -0500 Subject: [PATCH v2 2/2] Add a test for the search_path length limit Discussion: https://postgr.es/m/3538A21B-9257-42A9-A363-058DD5AE51D3@yesql.se --- src/test/regress/expected/guc.out | 37 +++++++++++++++++++++++++++++++ src/test/regress/sql/guc.sql | 26 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out index d429e00985b..bf084df5aab 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -1010,3 +1010,40 @@ SELECT name FROM tab_settings_flags (0 rows) DROP TABLE tab_settings_flags; +-- A GUC_REPORT string such as search_path must fit in a ParameterStatus +-- message that libpq accepts, even after conversion to the client encoding. +-- The longest value works, longer ones fail for one name or many names. +SELECT length(set_config('search_path', repeat('a', 7486), false)); + length +-------- + 7486 +(1 row) + +DO $$ +DECLARE + detail text; +BEGIN + BEGIN + PERFORM set_config('search_path', repeat('a', 7487), false); + EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE 'set_config: %', detail; + END; + BEGIN + EXECUTE 'SET search_path = ' || + (SELECT string_agg(lpad(i::text, 63, 'x'), ', ') + FROM generate_series(1, 200) i); + EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE 'SET: %', detail; + END; +END $$; +NOTICE: set_config: The maximum length is 7486 bytes. +NOTICE: SET: The maximum length is 7486 bytes. +SELECT length(current_setting('search_path')); + length +-------- + 7486 +(1 row) + +RESET search_path; diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index dd8fe84b7cc..a811b41c7bf 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -409,3 +409,29 @@ SELECT name FROM tab_settings_flags WHERE no_reset AND NOT no_reset_all ORDER BY 1; DROP TABLE tab_settings_flags; + +-- A GUC_REPORT string such as search_path must fit in a ParameterStatus +-- message that libpq accepts, even after conversion to the client encoding. +-- The longest value works, longer ones fail for one name or many names. +SELECT length(set_config('search_path', repeat('a', 7486), false)); +DO $$ +DECLARE + detail text; +BEGIN + BEGIN + PERFORM set_config('search_path', repeat('a', 7487), false); + EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE 'set_config: %', detail; + END; + BEGIN + EXECUTE 'SET search_path = ' || + (SELECT string_agg(lpad(i::text, 63, 'x'), ', ') + FROM generate_series(1, 200) i); + EXCEPTION WHEN invalid_parameter_value THEN + GET STACKED DIAGNOSTICS detail = PG_EXCEPTION_DETAIL; + RAISE NOTICE 'SET: %', detail; + END; +END $$; +SELECT length(current_setting('search_path')); +RESET search_path; -- 2.37.1 (Apple Git-137.1)