Re: ORDER BY with EXCEPT?

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ORDER BY with EXCEPT?
Date: 2009-02-20 02:00:55
Message-ID: 499E0ED7.6070306@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David E. Wheeler wrote:
> On Feb 19, 2009, at 5:45 PM, Andrew Dunstan wrote:
>
>> "A limitation of this feature is that an ORDER BY clause applying to
>> the result of a UNION, INTERSECT, or EXCEPT clause can only specify
>> an output column name or number, not an expression."
>>
>> Why not just say "order by 1" ?
>
> Well, in this case, I wanted the order to be the same as in the array
> that was passed.

Yeah. you can do it like this:

select foo from (
SELECT quote_ident($2[i]) as foo, i
FROM generate_series(1, array_upper($2, 1)) AS s(i)
EXCEPT
SELECT quote_ident(p.proname)
FROM pg_catalog.pg_proc p
JOIN pg_catalog.pg_namespace n
ON p.pronamespace = n.oid
AND quote_ident(n.nspname) = quote_ident($1)
ORDER BY i ) x;

>
> At any rate, your quotation of this documentation that I obviously
> missed answers my question. In the meantime, I got a different version
> with a LEFT JOIN to do what I want, so I don't need the EXCEPT at all.
> I just posted here because it looked like a bug. And though it's
> clearly not, since it's documented, it is kinda weird…
>
>

There are many odd corners, unfortunately.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2009-02-20 02:58:18 Re: pg_restore new option -m
Previous Message David E. Wheeler 2009-02-20 01:57:05 Re: ORDER BY with EXCEPT?