PostgreSQL:无法对某些数据类型使用 DISTINCT
我有一个名为 _sample_table_delme_data_files
的表,其中包含一些重复项。我想将其记录(不重复)复制到 data_files 中:
INSERT INTO data_files (SELECT distinct * FROM _sample_table_delme_data_files);
ERROR: could not identify an ordering operator for type box3d
HINT: Use an explicit ordering operator or modify the query.
问题是,PostgreSQL 无法比较(或排序)box3d 类型。我如何提供这样的排序运算符,以便我只能将不同的值放入我的目标表中?
预先感谢,
亚当
I have a table called _sample_table_delme_data_files
which contains some duplicates. I want to copy its records, without duplicates, into data_files
:
INSERT INTO data_files (SELECT distinct * FROM _sample_table_delme_data_files);
ERROR: could not identify an ordering operator for type box3d
HINT: Use an explicit ordering operator or modify the query.
Problem is, PostgreSQL can not compare (or order) box3d
types. How do I supply such an ordering operator so I can get only the distinct into my destination table?
Thanks in advance,
Adam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不添加运算符,您可以尝试使用其输出函数将
box3d
数据转换为文本,例如:编辑下一步是:将其转换回
box3d
:(我的系统上没有
box3d
,所以它未经测试。)If you don't add the operator, you could try translating the
box3d
data to text using its output function, something like:Edit The next step is: cast it back to
box3d
:(I don't have
box3d
on my system so it's untested.)数据类型 box3d 没有用于 DISTINCT 操作的运算符。您必须创建运算符,或者询问PostGIS-项目,也许有人已经解决了这个问题。
The datatype box3d doesn't have an operator for the DISTINCT-operation. You have to create the operator, or ask the PostGIS-project, maybe somebody has already fixed this problem.
最后被同事解决了。
让我们看看有多少重复项:
现在,我们将在源表中添加另一列,以帮助我们区分相似的行:
我们现在可以看到重复项:
并删除它们:
让我们看看它是否有效:
删除辅助列:
插入剩余的列行写入目标表:
Finally, this was solved by a colleague.
Let's see how many dups are there:
Now, we shall add another column to the source table to help us differentiate similar rows:
We can now see the dups:
And remove them:
Let's see it worked:
Remove the auxiliary column:
Insert the remaining rows into the destination table: