【发布时间】:2021-06-23 18:50:48
【问题描述】:
我需要使用 anorm 在 PostgreSQL 中执行查询。为了处理授权,我必须设置角色和查询。我的查询如下。
set role myuser; select country from country_list
当直接在 postgress 中执行时,这工作正常。但是当通过 anorm 尝试时没有发现异常PSQLException: No results were returned by the query.
但是当 set role 命令被删除时,这工作正常。
代码运行良好
import anorm.SqlParser._
SQL("select country from country_list").as(str("name").*)
代码抛出异常
import anorm.SqlParser._
SQL("set role myuser; select country from country_list").as(str("name").*)
例外
org.postgresql.util.PSQLException: No results were returned by the query.
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:115)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at anorm.Sql.$anonfun$resultSet$2(Anorm.scala:78)
【问题讨论】: