luckyframework / luckyframework/avram

Distinct doesn't work when using upper

Open
#679 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

```crystal
# works
UserQuery.new
.preload_role
.where_groups(GroupQuery.new.id.in(groups.map &.id))
.email
.upper
.asc_order

# works
UserQuery.new
.preload_role
.where_groups(GroupQuery.new.id.in(groups.map &.id))
.email
.asc_order
.distinct

# doesn't work (for SELECT DISTINCT, ORDER BY expressions must appear in select list)
UserQuery.new
.preload_role
.where_groups(GroupQuery.new.id.in(groups.map &.id))
.email
.upper
.asc_order
.distinct
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the UserQuery.new chain shown in the issue and run the three reproduction cases against PostgreSQL to compare the generated queries. Trace how .upper, .asc_order, and .distinct are combined; done means the final query executes without the SELECT DISTINCT/ORDER BY error while preserving the demonstrated ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.