From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: aceonline@gmx.de, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #16510: Count Distinct with non distinct column in combination with string constants throws error
Date: Thu, 25 Jun 2020 10:32:34 -0400
Message-ID: <2270140.1593095554@sss.pgh.pa.us> (raw)
In-Reply-To: <5CF2CF6C-8951-4CA1-980C-94F369B7EE86@yesql.se>
References: <16510-755ed3d371542beb@postgresql.org>
<5CF2CF6C-8951-4CA1-980C-94F369B7EE86@yesql.se>
Daniel Gustafsson <daniel@yesql.se> writes:
> 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
The reason for this might be a little more obvious if you wrote the
implicit row constructor explicitly, ie
SELECT COUNT(DISTINCT ROW(testtable.column2, 'blub')) FROM public.testtable;
The row's datatype is indeterminate as-specified.
Perhaps there's room to argue that we should allow 'unknown' to decay to
'text' automatically in this context, but I'm not in a big hurry to do
that. It seems better to make people be explicit about which datatype
they intend inside such complex, infrequently-used constructs.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, daniel@yesql.se, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16510: Count Distinct with non distinct column in combination with string constants throws error
In-Reply-To: <2270140.1593095554@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox