首页 > 解决方案 > 对 Cube 数据类型列执行 Postgresql 查询时出错

问题描述

我是 Postgesql 的新手。我创建了一个表,其中包含(Id integer, name text, url text, vector cube)名为images.

<->现在我想使用(euclidean distance ) 运算符搜索 K 最接近新立方体变量的值。我的查询如下(我假设数据列是 3D):

Select * 
from images 
order by vector <-> cube(array[0.5, 0.3, 0.2]) 
limit 5

但是会出现以下错误:

ERROR:  operator does not exist: cube <-> cube
LINE 1: Select * from test order by data <-> cube(array[0.5, 0.3, 0.2...
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
SQL state: 42883
Character: 38

请帮助我。谢谢。我正在使用 Ubuntu 16.04.6 LTS 和 Postgresql 版本 9.5.19。

我的表格和错误的屏幕截图附在下面:

在此处输入图像描述

在此处输入图像描述

标签: postgresqlpostgresql-9.5

解决方案


postgres 9.5 中的cube扩展没有<->操作符。你可以cube_distance改用。以下是相关文档:

https://www.postgresql.org/docs/9.5/cube.html


推荐阅读