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

count(distinct(_)) is not generated for _.distinct.size #436

Closed
exlevan opened this issue Jul 10, 2016 · 1 comment
Closed

count(distinct(_)) is not generated for _.distinct.size #436

exlevan opened this issue Jul 10, 2016 · 1 comment
Labels

Comments

@exlevan
Copy link

exlevan commented Jul 10, 2016

Version: 0.7.0

Steps to reproduce the behavior

Run the following code:

import io.getquill._

case class user(id: Long, name: String, age: Int)

object Main extends App {
  val db = source(new SqlMirrorSourceConfig[naming.Escape]("db"))
  val q = quote {
    query[user].map(u => u.name).distinct.size
  }
  println(db.run(q).sql)
}

Expected behavior

SELECT COUNT(DISTINCT "u"."name") FROM "user" "u"

Actual behavior

SELECT DISTINCT COUNT("u"."name") FROM "user" "u"

@getquill/maintainers

@fwbrasil fwbrasil added the bug label Jul 10, 2016
@fwbrasil
Copy link
Collaborator

workaround:

  import testContext._

  implicit class CountDistinct[T](q: Query[T]) {
    def countDistinct = quote(q.map(v => infix"count(distinct $v))".as[Long]))
  }
  case class User(name: String)

  val q = quote {
    query[User].map(_.name).countDistinct
  }

jilen pushed a commit that referenced this issue Jun 11, 2024
Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants