首页 > 解决方案 > org.postgresql.util.PSQLException:错误:没有为窗口函数实现 DISTINCT

问题描述

这个 SQL

SELECT COUNT(DISTINCT(FOO)) over (PARTITION BY NULL) as bar

导致错误

org.postgresql.util.PSQLException: ERROR: DISTINCT is not implemented for window functions

在stackoverflow上解决这个错误似乎没有任何答案。

标签: sqlpostgresql

解决方案


固定的

将 SQL 更改为SELECT COUNT(FOO) over (PARTITION BY NULL) as bar

Postgres 不喜欢在 COUNT 之后有 DISTINCT,并且当没有 DISTINCT 时会将其视为一个函数。


推荐阅读