【问题标题】:Cannot run slick queries on postgis with slick-pg无法使用 slick-pg 在 postgis 上运行 slick 查询
【发布时间】:2020-08-28 15:50:03
【问题描述】:

在我的项目中,我有必要将位置数据保存在表格中,所以我创建了下表

create table if not exists public.person(
  email varchar(255) not null primary key,
  name varchar(255) not null,
  surname varchar(255) not null,
  location point
)

连同相关实体/表:

case class Person(email: String, name: String, surname: String, location: Point)
class People(tag: Tag) extends Table[Person](tag, "person") {

  def email: Rep[String] = column[String]("email")
  def name: Rep[String] = column[String]("name")
  def surname: Rep[String] = column[String]("surname")
  def location: Rep[Point] = column[Point]("location")

  def pk = primaryKey("pk", email)

  def * : ProvenShape[Person] =
    (email, name, surname, location) <> (Person.tupled, Person.unapply)

}

然后我按照此处的说明创建了我的扩展配置文件:

trait ExtendedProfile
    extends ExPostgresProfile
    with PgDateSupport
    with PgDate2Support
    with PgPostGISSupport {

  override val api: API = new API {}

  trait API
      extends super.API
      with SimpleDateTimeImplicits
      with DateTimeImplicits
      with PostGISImplicits
      with PostGISAssistants

  val plainAPI = new API
    with ByteaPlainImplicits
    with Date2DateTimePlainImplicits
    with PostGISPlainImplicits {}
}

object ExtendedProfile extends ExtendedProfile

每当我尝试在数据库中插入一个人时,我都会收到以下错误:org.postgresql.util.PSQLException: ERROR: column \"location\" is of type point but expression is of type bytea

我错过了什么吗?这是我第一次使用postgis,但是如果我直接查询数据库我可以插入点数据就好了。

【问题讨论】:

    标签: postgresql scala postgis slick-pg


    【解决方案1】:

    试试这个

    create table if not exists public.person(
      email varchar(255) not null primary key,
      name varchar(255) not null,
      surname varchar(255) not null,
      location geometry
    )
    

    Point 不是 PostGIS 类型slick-pg 仅支持 PostGIS 类型。 PostGIS中的所有形状都用geometry类型表示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-15
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多