DISTINCT ON

From: Emmanuel Cecchet <manu(at)asterdata(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: DISTINCT ON
Date: 2009-11-04 03:17:06
Message-ID: 4AF0F232.7020405@asterdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

It looks like Postgres has a restriction in DISTINCT ON queries where the DISTINCT ON expressions must match the left side of the ORDER BY list. The issue is that if a DISTINCT ON ... has multiple instances of a particular expression, this check doesn't seem to fire correctly.

For example, this query returns an error (but I guess it shouldn't):

SELECT DISTINCT ON ('1'::varchar, '1'::varchar) a FROM (SELECT 1 AS a) AS a ORDER BY '1'::varchar, '1'::varchar, '2'::varchar;

And this query doesn't return an error (but I guess it should):

SELECT DISTINCT ON ('1'::varchar, '2'::varchar, '1'::varchar) a FROM (SELECT 1 AS a) AS a ORDER BY '1'::varchar, '2'::varchar, '2'::varchar;

Am I misunderstanding something or is there a bug?

Thanks for the help
Emmanuel

--
Emmanuel Cecchet
Aster Data
Web: http://www.asterdata.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2009-11-04 03:17:51 Re: Architecture of walreceiver (Streaming Replication)
Previous Message Ron Mayer 2009-11-04 02:35:52 Re: EOL for 7.4?