FIXED: Ecto 3.9 selected_as feature not working as expected

First of all congrats with 3.9 release. :tada:

I was waiting on select_as feature particularly. But after update it does not work (as i was expecting).

# old code:
query
|> select_merge([txn: t], %{
  time:
    fragment(
      "DATE_TRUNC('day', ? AT TIME ZONE 'utc' AT TIME ZONE 'Europe/Riga')::date",
      t.inserted_at
    )
})
|> group_by(
  [txn: t],
  fragment(
    "DATE_TRUNC('day', ? AT TIME ZONE 'utc' AT TIME ZONE 'Europe/Riga')::date",
    t.inserted_at
  )
)
# tried new code:
query
|> select_merge([txn: t], %{
  time:
    selected_as(fragment(
      "DATE_TRUNC('day', ? AT TIME ZONE 'utc' AT TIME ZONE 'Europe/Riga')::date",
      t.inserted_at
    ), :time)
})
|> group_by(selected_as(:time))
# error
invalid alias: `:time`. Use `selected_as/2` to define aliases in the outer most `select` expression.

if I understand correctly selected_as is not supported with select_merge. What was reasoning behind not allowing it? Some technical or philosophical limitations? Will it be supported in near future?

Thanks.

1 Like

Please open up an issue!

2 Likes

Fixed: selected_as suppoert within select_merge · Issue #4011 · elixir-ecto/ecto · GitHub

2 Likes