Skip to content

Commit

Permalink
Fix super type modifier handling (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Aug 27, 2024
1 parent 02d816b commit 5924c18
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/array.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ defmodule Postgrex.Extensions.Array do
data::binary>> = binary

# decode_list/2 defined by TypeModule
type =
sub_type_with_mod =
case type do
{extension, sub_oids, sub_types} -> {extension, sub_oids, sub_types, var!(mod)}
extension -> {extension, var!(mod)}
end

flat = decode_list(data, type)
flat = decode_list(data, sub_type_with_mod)

unquote(__MODULE__).decode(dims, flat)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/multirange.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ defmodule Postgrex.Extensions.Multirange do
<<_num_ranges::int32(), ranges::binary>> = data

# decode_list/2 defined by TypeModule
type =
sub_type_with_mod =
case type do
{extension, sub_oids, sub_types} -> {extension, sub_oids, sub_types, nil}
extension -> {extension, nil}
end

bound_decoder = &decode_list(&1, type)
bound_decoder = &decode_list(&1, sub_type_with_mod)
unquote(__MODULE__).decode(ranges, bound_decoder, [])
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ defmodule Postgrex.Extensions.Range do
<<flags, data::binary>> = binary

# decode_list/2 defined by TypeModule
type =
sub_type_with_mod =
case type do
{extension, sub_oids, sub_types} -> {extension, sub_oids, sub_types, nil}
extension -> {extension, nil}
end

case decode_list(data, type) do
case decode_list(data, sub_type_with_mod) do
[upper, lower] ->
unquote(__MODULE__).decode(flags, [lower, upper])

Expand Down
6 changes: 6 additions & 0 deletions test/calendar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ defmodule CalendarTest do
test "decode time with precision", context do
assert [[~T[00:00:00.000]]] = query("SELECT time(3) '00:00:00'", [])
assert [[[~T[00:00:00.000]]]] = query("SELECT ARRAY[time(3) '00:00:00']", [])

assert [[[[~T[00:00:00.000], ~T[00:00:00.000]], [~T[01:00:00.000], ~T[01:00:00.000]]]]] =
query(
"SELECT ARRAY[ARRAY[time(3) '00:00:00', time(3) '00:00:00'], ARRAY[time(3) '01:00:00', time(3) '01:00:00']]",
[]
)
end

test "decode timetz", context do
Expand Down
21 changes: 21 additions & 0 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,27 @@ defmodule QueryTest do
}
]
] = query("SELECT '[2014-1-1,2014-12-31)'::tsrange", [])

assert [
[
[
%Postgrex.Range{
lower: ~N[2014-01-01 00:00:00.000000],
upper: ~N[2014-12-31 00:00:00.000000],
lower_inclusive: true,
upper_inclusive: false
},
%Postgrex.Range{
lower: ~N[2014-01-01 00:00:00.000000],
upper: ~N[2014-12-31 00:00:00.000000],
lower_inclusive: true,
upper_inclusive: false
}
]
]
]

query("SELECT ARRAY['[2014-1-1,2014-12-31)'::tsrange, '[2014-1-1,2014-12-31)'::tsrange]", [])
end

@tag min_pg_version: "14.0"
Expand Down

0 comments on commit 5924c18

Please sign in to comment.