本文介绍了使用Distinct时的PostGres错误:postgres错误:无法识别类型记录的排序运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**编辑**

没关系,只需要取出括号...

Nevermind, just needed to take out the parens...

我收到此错误:错误:尝试使用DISTINCT时无法识别类型记录
的排序运算符

I get this error: ERROR: could not identify an ordering operator for type recordwhen trying to use DISTINCT

以下是查询:

select DISTINCT(g.fielda, g.fieldb, r.type) 
from fields g LEFT JOIN types r ON g.id = r.id;

错误:

ERROR:  could not identify an ordering operator for type record
HINT:  Use an explicit ordering operator or modify the query.

********** Error **********

ERROR: could not identify an ordering operator for type record
SQL state: 42883
Hint: Use an explicit ordering operator or modify the query.


推荐答案

我认为您已经解决了,不想在 DISTINCT 之后加上括号。它们看起来应该参数化 DISTINCT ,但是它们实际上是用来使查询返回记录类型的单列而不是多列。然后, DISTINCT 运算符尝试处理该记录,发现您尚未在该记录上定义顺序。

As I think you've worked out, you don't want the parentheses after DISTINCT. They look like they should be parameterising DISTINCT, but they actually serve to make the query return a single column of record type instead of multiple columns. The DISTINCT operator then tries to work on the record and finds that you've not defined an ordering on that record.

如果您希望 DISTINCT 处理部分返回值,请使用 DISTINCT ON

If you want DISTINCT to work on a subset of your return values, use DISTINCT ON.

这篇关于使用Distinct时的PostGres错误:postgres错误:无法识别类型记录的排序运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:54