0
votes

I'm trying to run plain SQL with slick 3.1.0.

The following works:

   val q = sql"select name from users".as[String]

however if my sql is in a variable:

   val string2 : String = "select name from users"

how do I execute string2 using sql prefix? This doesn't work:

   sql+string2 
1

1 Answers

2
votes

Use interpolation within the string:

val q = sql"#$string2"

The #$ interpolator will use the literal string you're interpolating, so don't use it for user input - it won't quote or anything.

See this section of the docs for more details.