使用PostgreSQL时出现问题 [英] Slick issue when going with PostgreSQL

查看:131
本文介绍了使用PostgreSQL时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Scala项目中使用 slick 来查询一些表。

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()
      session.withTransaction{
        val query = Query(Addresses)
        println("Addresses: " + query.selectStatement)
}

我注意到schema.table的名称出现在 中,因此该语句为:

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

这当然是行不通的(我已经试图在PostgreSQL工具中运行它,我需要从表名中删除

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.

我仅指定表名:

对象地址扩展了Table [Address]( address)

并更改我的postgresql conf以在搜索时包括我的架构(看来,slick正在查找 public 仅限架构):

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'

,现在可以使用了。

这篇关于使用PostgreSQL时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆