Cristian Boariu Cristian Boariu - 1 month ago 8
Scala Question

Slick issue when going with PostgreSQL

I'm using slick in a scala project to query some tables.

//define table
object Addresses extends Table[Address]("assetxs.address") {
def id = column[Int]("id", O.PrimaryKey)
def street = column[String]("street")
def number = column[String]("number")
def zipcode = column[String]("zipcode")
def country = column[String]("country")
def * = id ~ street ~ number ~ zipcode ~ country <> (Address, Address.unapply _)

If I use any query of this table it does not work (it says it cannot find my table) so I went further and print out the query like:

implicit val session = Database.forURL("jdbc:postgresql://localhost:5432/postgres", driver = "org.postgresql.Driver", user="postgres", password="postgres").createSession()
val query = Query(Addresses)
println("Addresses: " + query.selectStatement)

I noticed that the name of the schema.table appears in
so the statement is:

select x2."id", x2."street", x2."number", x2."zipcode", x2."country"
from "assetxs.address" x2

which of course does not work (I've tried to run it in PostgreSQL tool and I needed to remove
from table name in order to have it working.

Can you please tell me if there is any slick option to not include
in any query when using table names?


In the end I was able to solve this issue.

I specify the table name only:

object Addresses extends Table[Address]("address")

and change my postgresql conf to include my schema when searching (it seems that slick is looking on public schema only):

search_path = '"$user",assetxs,public'

and now it works.