postgresql - 无法使用 slick-pg 在 postgis 上运行 slick 查询
问题描述
在我的项目中,我有必要将位置数据保存在表格中,因此我创建了下表
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,但是如果我直接查询数据库我可以插入点数据就好了。
解决方案
尝试这个
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
推荐阅读
- python - 使用 Python Openpyxl 和 For 循环连接 Excel 中的两个单元格
- python-3.x - 如何在 python 中将数据编码为 der?
- angular6 - 错误:没有名称的表单控件的值访问器:“答案”
- java - Java 不再适用于 Visual Studio Code
- python - 警告:带约束的 tensorflow 已弃用,将在未来版本中删除
- qbasic - 在 Qbasic 中,如何让我的厘米数显示到小数点后一位。73.53 而不是 73.53315
- python - 在 Python 中将 USB 视频捕获设备友好名称与 OpenCV 端口号相关联
- d3.js - 如何在箱线图 dc.js 中仅显示有限数量的记录
- r - 添加“哔”列
- reactjs - 使用 useState 挂钩后的陈旧数据