Skip to content

Commit

Permalink
Comment on how range retrieval works (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanl authored Jun 23, 2023
1 parent 9037442 commit 8180fca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/postgrex/builtins.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ defmodule Postgrex.Range do
@moduledoc """
Struct for PostgreSQL `range`.
Note that PostgreSQL itself does not return ranges exactly as stored:
`SELECT '(1,5)'::int4range` returns `[2,5)`, which is equivalent in terms
of the values included in the range ([PostgreSQL docs](https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-IO)).
When selecting data, this struct simply reflects what PostgreSQL returns.
## Fields
* `lower`
Expand Down
3 changes: 3 additions & 0 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ defmodule QueryTest do

@tag min_pg_version: "9.2"
test "decode range", context do
# These do not appear to match what is selected, but that's because
# PostgreSQL itself returns range values this way.
# `SELECT '(1,5)'::int4range` returns `[2,5)`.
assert [[%Postgrex.Range{lower: 2, upper: 5, lower_inclusive: true, upper_inclusive: false}]] =
query("SELECT '(1,5)'::int4range", [])

Expand Down

0 comments on commit 8180fca

Please sign in to comment.