Re: BUG #16510: Count Distinct with non distinct column in combination with string constants throws error

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: aceonline(at)gmx(dot)de, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16510: Count Distinct with non distinct column in combination with string constants throws error
Date: 2020-06-25 14:18:59
Message-ID: 5CF2CF6C-8951-4CA1-980C-94F369B7EE86@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> On 25 Jun 2020, at 15:02, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:

> SELECT
> COUNT( DISTINCT (testtable.column2, 'blub') )
> FROM
> public.testtable;

PostgreSQL doesn't know which datatype you expect 'blub' to be, as it isn't
related to the testtable relation in your query. If you cast to the datatype
of your choice you will get the expected result.

postgres=# SELECT COUNT(DISTINCT(testtable.column2, 'blub')) FROM public.testtable;
ERROR: could not identify a comparison function for type unknown
postgres=# SELECT COUNT(DISTINCT(testtable.column2, 'blub'::varchar)) FROM public.testtable;
count
-------
1
(1 row)

cheers ./daniel

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pierre Mantha 2020-06-25 14:31:10 Re: BUG #16509: Unable to change from 32 bit to 64 bit
Previous Message Axel Zellner 2020-06-25 13:43:28 Bug: Postgresql with Postgis: Different result in coordinate conversion NAV4 <=> WGS84 in Linux and Windows