0

I'm trying to get basic plain SQL example working in Slick 3, on Postgres but with custom DB schema, say local instead of default public one. I have hard time inserting the row as executing the following

sqlu"INSERT INTO schedule(user_id, product_code, run_at)  VALUES ($userId, $code, $nextRun)"

says

org.postgresql.util.PSQLException: ERROR: relation "schedule" does not exist

The table is in place because when I prefix schedule with local. in the insert statement it works as expected. How can I get correct schema provided to this query?

I'm using it as part of akka-projection handler and all the projection internals like maintaining offsets work as expected on local schema.

I cannot simply put schema as a variable as it errors while resolving parameters:

sqlu"INSERT INTO ${schema}.schedule(user_id, product_code, run_at)  VALUES ($userId, $code, $nextRun)"
Michal Ostruszka
  • 2,089
  • 2
  • 20
  • 23
  • 1
    How about at JDBC connection level? https://stackoverflow.com/questions/4168689/is-it-possible-to-specify-the-schema-when-connecting-to-postgres-with-jdbc#4820666 – Mateusz Kubuszok Nov 02 '21 at 19:43
  • Crap, too many configs. Didn't have schema specified at this exact one. So not really that, but thanks for pointing me in the right direction – Michal Ostruszka Nov 03 '21 at 06:37

1 Answers1

1

You can insert schema name using #${value}:

sqlu"INSERT INTO #${schema}.table ..."

kardapoltsev
  • 1,053
  • 8
  • 14