通过架构内的扩展添加的访问运算符

Pat*_*sen 4 postgresql jdbc postgresql-9.4

我正在编写一个使用 postgres 的应用程序。每个微服务在数据库中使用自己的架构。

所以连接到我使用这个 jdbc 字符串的数据库模式:

jdbc:postgresql://${db.host}/${db.name}?currentSchema=${schema}
Run Code Online (Sandbox Code Playgroud)

这种工作原理,因此每个 sql 语句都可以使用架构内的表,而不会出现意外访问其他服务架构的危险。

但在一种模式中,我想使用地球距离扩展。我只设法在没有设置架构的情况下安装它,当我在没有 currentSchema 参数的情况下连接到数据库时,我可以访问 <@> 运算符来计算距离。但是使用参数 postgres 抱怨它无法找到运算符。

当我连接 currentSchema 参数时,有没有办法访问公共命名空间中的运算符?

我有点迷失在这里:-(

小智 6

您可以在调用运算符时对运算符进行架构限定。

例如,而不是写

SELECT current <@> destination
Run Code Online (Sandbox Code Playgroud)

你可以写:

SELECT current operator(public.<@>) destination
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅运算符调用