Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created May 17, 2013 15:19
Show Gist options
  • Select an option

  • Save debasishg/5599764 to your computer and use it in GitHub Desktop.

Select an option

Save debasishg/5599764 to your computer and use it in GitHub Desktop.
Problem with Slick generating sql for count with hsqldb
// sample query using count
val c =
for {
d <- Databases if (d.name like s"$name%") && (d.hasDistinctCount === true)
} yield t.count
println(c.selectStatement)
// generates this sql for h2
select select count(1) from "Databases" x2 where (x2."name" like 'world%') and (x2."hasDistinctCount" = true)
// generates this incorrect statement for hsqldb
select select count(1) from (VALUES (0)) from "Databases" x2 where (x2."name" like cast('world%' as varchar(16777216))) and (x2."hasDistinctCount" = true)
@debasishg

Copy link
Copy Markdown
Author

If I change the query to

val c =
  (for {
    t <- Databases if (t.name like s"$name%") && (t.hasDistinctCount === true)
  } yield t.name.count)

then I get following statement

select count(x2."name") from "Databases" x2 where (x2."name" like cast('world%' as varchar(16777216))) and (x2."hasDistinctCount" = true)

which is syntactically correct. But the "like" query doesn't work properly. If there r 2 records with name = "world1" and "world2", the select returns a count of 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment