user773366
user773366

Reputation:

Like clause not working with int column in slick

Slick doesn't seem to support like clauses on int columns. The following code where Status.code is of int type doesn't seem to work. Would there be a workaround for this?

val query = for {
  s <- Status if s.code like "1%"
} yield (s)

Upvotes: 0

Views: 475

Answers (1)

Biswanath
Biswanath

Reputation: 9185

Can you post your Status class definitation .If code is type column[Int] your code should be giving error as like works on column[string].

The below snippet works for doing a like on integer field.

class Coffees(tag: Tag) extends Table[(String, Int)](tag, "COFFEES") {
    def name = column[String]("NAME")
    def status = column[Int]("STATUS")
    def * = (name,status) 
}

This is data insert and querying part

coffees ++= Seq(
        ("Colombian",         101),
        ("French_Roast",       49),
        ("Espresso",          150),
        ("Colombian_Decaf",   101),
        ("French_Roast_Decaf", 49)
      ) 

for( coffee <- coffees if coffee.status.asColumnOf[String] like "1%" ) 
    println(coffee)

Upvotes: 2

Related Questions