diff --git a/src/array_parsing.jl b/src/array_parsing.jl index 919356f..eabde12 100644 --- a/src/array_parsing.jl +++ b/src/array_parsing.jl @@ -70,7 +70,10 @@ function parse_unquoted(code::Base.CodeUnits{UInt8, String}, pos::Ref{Int}) pos[] += 1 end end - return String(strip(String(buf))) + # The server quotes any element that contains ASCII whitespace, so an + # unquoted element runs to the delimiter. Unicode spaces such as U+00A0 + # are never quoted and belong to the element: do not strip. + return String(buf) end function parse_bool_token(token::String) diff --git a/test/runtests.jl b/test/runtests.jl index f3c5bb7..4c99992 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1371,6 +1371,13 @@ include("trim_compile_tests.jl") bracket_param = ["a]b", "x[1]", "]", "plain"] bracket_row = only(Tables.rowtable(DBInterface.execute(conn, raw"SELECT $1::text[] AS arr", (bracket_param,)))) @test bracket_row.arr == bracket_param + # PostgreSQL quotes an element only for ASCII whitespace, so + # other whitespace at an element's edge arrives unquoted + edge_ws = ["\u00a0lead", "trail\u00a0", "\u2028both\u3000", "a b"] + edge_row = only(Tables.rowtable(DBInterface.execute(conn, + raw"SELECT ARRAY[E'\u00a0lead', E'trail\u00a0', E'\u2028both\u3000', 'a b'] AS arr"))) + @test edge_row.arr == edge_ws + @test DBInterface.execute(conn, raw"SELECT $1::text[] AS arr", (edge_ws,), NamedTuple{(:arr,), Tuple{Vector{String}}}).arr == edge_ws array_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{1,NULL,3}'::int[] AS arr"))) @test isequal(array_row.arr, Union{Missing, Int32}[1, missing, 3]) nested_row = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '{{1,2},{3,4}}'::int[] AS arr")))