Slick plain SQL escape PostgreSQL json 函数
Slick plain SQL escape PostgreSQL json function
我正在尝试转义此查询中的 ?|
运算符:
val data = sql"""
SELECT ......
FROM .......
WHERE table.column ?| array['23', '12']
""".as[Int].head
db.run(data)
但是 ?|
运算符在查询中被翻译为 |
(在数据库查询日志中检查)并且它显然会生成错误
ERROR: syntax error at or near "" at character 735
我试过 #?|
和 $?|
都没有成功
?
是 JDBC 中参数的占位符(即 Slick 之后的级别)。你可以转义 ?
specifically for PostgreSQL as ??|
. There's useful discussion of this in SO 14779896 - Does the JDBC spec prevent '?' from being used as an operator.
此约定的替代方法是使用非符号替代方法:jsonb_exists_any
。例如,
WHERE jsonb_exists_any(table.column, array['23', '12'])
我正在尝试转义此查询中的 ?|
运算符:
val data = sql"""
SELECT ......
FROM .......
WHERE table.column ?| array['23', '12']
""".as[Int].head
db.run(data)
但是 ?|
运算符在查询中被翻译为 |
(在数据库查询日志中检查)并且它显然会生成错误
ERROR: syntax error at or near "" at character 735
我试过 #?|
和 $?|
都没有成功
?
是 JDBC 中参数的占位符(即 Slick 之后的级别)。你可以转义 ?
specifically for PostgreSQL as ??|
. There's useful discussion of this in SO 14779896 - Does the JDBC spec prevent '?' from being used as an operator.
此约定的替代方法是使用非符号替代方法:jsonb_exists_any
。例如,
WHERE jsonb_exists_any(table.column, array['23', '12'])