Re: SELECT DISTINCT is picky about constants

Lists: pgsql-performance
From: Andreas Pflug <Andreas(dot)Pflug(at)web(dot)de>
To: pgsql-performance(at)postgresql(dot)org
Subject: SELECT DISTINCT is picky about constants
Date: 2003-02-04 12:15:46
Message-ID: 3E3FAEF2.5080302@web.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

The query
SELECT DISTINCT keycol, 'constant' FROM myTable
or
SELECT DISTINCT keycol, NULL FROM myTable

will result in an error message (7.3.1)

Unable to identify an ordering operator '<' for type "unknown"
Use explicit ordering operator or modify query

If I use 'constant'::varchar or NULL::varchar everything's fine.
Unfortunately, this SELECT DISTINCT will appear quite often in my app.

I'd rather like PostgreSQL to use implicit type casting for such
constants. The final type chosen doesn't matter anyway and life would be
easier.


From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Andreas Pflug <Andreas(dot)Pflug(at)web(dot)de>
Cc: Postgresql Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: SELECT DISTINCT is picky about constants
Date: 2003-02-04 14:29:13
Message-ID: 1044368952.80167.6.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On Tue, 2003-02-04 at 07:15, Andreas Pflug wrote:
> The query
> SELECT DISTINCT keycol, 'constant' FROM myTable
> or
> SELECT DISTINCT keycol, NULL FROM myTable
>
> will result in an error message (7.3.1)
>
> Unable to identify an ordering operator '<' for type "unknown"
> Use explicit ordering operator or modify query
>
> If I use 'constant'::varchar or NULL::varchar everything's fine.
> Unfortunately, this SELECT DISTINCT will appear quite often in my app.
>
> I'd rather like PostgreSQL to use implicit type casting for such
> constants. The final type chosen doesn't matter anyway and life would be
> easier.

How about:

SELECT keycol, NULL FROM (SELECT DISTINCT keycol FROM myTable) AS tab;

Might even be quicker as you won't have to do any comparisons against
the constant.

--
Rod Taylor <rbt(at)rbt(dot)ca>

PGP Key: http://www.rbt.ca/rbtpub.asc