我们希望获得具有重复项的表的唯一条目。
简化后,我们有以下表格设置:
id(uuid) | title (character) | fingerprint (uuid)| created_at(timestamp)
123-0-1-321 | Dogs | 123-0-1-321 | 2021-12-06 00:00:01
344-0-1-321 | Dog | 123-0-1-321 | 2018-13-06 00:00:01
888-0-1-321 | Cats | 888-0-1-321 | 2020-12-06 00:00:01
777-0-1-321 | Birds | 999-0-1-321 | 2019-12-06 00:00:01
555-0-1-321 | Birds1 | 999-0-1-321 | 2022-12-06 00:00:01
我们希望通过指纹获得不同的值。我们目前通过
DISTINCT ON
运行良好:
SELECT DISTINCT ON (fingerprint) *
FROM "tile"
ORDER BY fingerprint, updated_at DESC;
但现在我们面临着一个通过“标题”(使用搜索向量)进行搜索的问题。问题是,我们希望根据搜索相关性对结果进行排序。但由于
DISTINCT ON fingerprint
我们总是要使用
fingerprint
作为第一
ORDER BY
参数因此,按参数排序的二阶搜索相关性不再有效。
我更喜欢这样的东西,但它不起作用:
SELECT FIRST(id), fingerprint
FROM "tile"
GROUP BY fingerprint
ORDER BY search_relevance;
MIN(id)
和
MAX(id)
当然也不起作用,因为
id
是一个uuid字段。