Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/execute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ end
_param(x::Missing) = x
_param(::Nothing) = missing
_param(x::AbstractVector{UInt8})::String = string("\\x", bytes2hex(x))
# json/jsonb results are lazy JSON values; bind them (and raw JSONText) as
# their JSON text, not as Julia's display of them.
_param(x::JSON.LazyValue)::String = JSON.parse(x, JSON.JSONText).value
_param(x::JSON.JSONText)::String = x.value
# convert to postgres array literal syntax: { x, y, z }
# strings must be double-quoted and double quotes and backslashes escaped
# missing values are NULL
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,15 @@ include("trim_compile_tests.jl")
@test array_types_row.date_array == Date[Date(2024, 1, 28)]
@test isequal(array_types_row.numeric_array, [Postgres.API.parse_numeric("123.45"), missing])
@test JSON.parse(only(array_types_row.jsonb_array))["a"] == 1
# JSON values read from the server bind back as their JSON text
json_text = """{"n": 12345678901234567890.5, "s": "é"}"""
json_value = only(Tables.rowtable(DBInterface.execute(conn, "SELECT '$json_text'::jsonb AS j"))).j
json_row = only(Tables.rowtable(DBInterface.execute(conn,
raw"SELECT $1::text AS t, $2::jsonb[]::text AS a, $3::json::text AS raw",
(json_value, [json_value.n, missing], JSON.JSONText("[1, 2]")))))
@test json_row.t == json_text
@test json_row.a == "{12345678901234567890.5,NULL}"
@test json_row.raw == "[1, 2]"
end

@testset "Binary Array Round Trips" begin
Expand Down
Loading