Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested super type modifier handling #705

Merged
merged 2 commits into from
Aug 27, 2024
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: 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]", [])
greg-rychlewski marked this conversation as resolved.
Show resolved Hide resolved
end

@tag min_pg_version: "14.0"
Expand Down
Loading