Ecto: Ecto.Query! with ARRAY_AGG returning random string

Created on 3 Dec 2018  路  1Comment  路  Source: elixir-ecto/ecto

Environment

  • Elixir version (elixir -v):
Erlang/OTP 21 [erts-10.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.7.4 (compiled with Erlang/OTP 21)
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.):
    PostgreSQL 10.5
  • Ecto version (mix deps): 2.2.11
  • Operating system: macOS Mojave 10.14.1

Current behavior

Repo.query!("SELECT hash, ARRAY_AGG(DISTINCT image_url), page_id, ARRAY_AGG(id) FROM captures WHERE hash IS NOT null GROUP BY hash, page_id HAVING COUNT(1) > 1 AND COUNT(DISTINCT image_url) > 1")
[
  [
    "36184bef2156c61f",
    ["15_d60d90e0-f4a3-11e8-a970-e7d3d5226480.png",
     "9_b9c6cbe0-f4a3-11e8-a970-e7d3d5226480.png"],
    2,
    [15, 9]
  ],
  [
    "695edc8caf53ec1d",
    ["13_ca4e3610-f4a3-11e8-a970-e7d3d5226480.png",
     "7_ad04ce20-f4a3-11e8-a970-e7d3d5226480.png"],
    3,
    '\r\a'
  ]
]

Expected behavior

[
  [
    "36184bef2156c61f",
    ["15_d60d90e0-f4a3-11e8-a970-e7d3d5226480.png",
     "9_b9c6cbe0-f4a3-11e8-a970-e7d3d5226480.png"],
    2,
    [15, 9]
  ],
  [
    "695edc8caf53ec1d",
    ["13_ca4e3610-f4a3-11e8-a970-e7d3d5226480.png",
     "7_ad04ce20-f4a3-11e8-a970-e7d3d5226480.png"],
    3,
    [13, 7]
  ]
]

Most helpful comment

Single quotes in Elixir represent a list of characters. When in doubt, you can put the term on IEx preceeded by an i:

iex(1)> i '\r\a'
Term
  '\r\a'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent valid
  ASCII characters. Conventionally, such lists of integers are referred to
  as "charlists" (more precisely, a charlist is a list of Unicode codepoints,
  and ASCII is a subset of Unicode).
Raw representation
  [13, 7]
Reference modules
  List
Implemented protocols
  IEx.Info, Inspect, String.Chars, List.Chars, Collectable, Enumerable

In other words, it is the list [13, 7], it is just printed between single quotes. :)

>All comments

Single quotes in Elixir represent a list of characters. When in doubt, you can put the term on IEx preceeded by an i:

iex(1)> i '\r\a'
Term
  '\r\a'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent valid
  ASCII characters. Conventionally, such lists of integers are referred to
  as "charlists" (more precisely, a charlist is a list of Unicode codepoints,
  and ASCII is a subset of Unicode).
Raw representation
  [13, 7]
Reference modules
  List
Implemented protocols
  IEx.Info, Inspect, String.Chars, List.Chars, Collectable, Enumerable

In other words, it is the list [13, 7], it is just printed between single quotes. :)

Was this page helpful?
0 / 5 - 0 ratings