Re: Suggestion for aggregate function - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Suggestion for aggregate function
Date
Msg-id 87fzrr1frt.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: Suggestion for aggregate function  (Manfred Koizar <mkoi-pg@aon.at>)
Responses Re: Suggestion for aggregate function  (Manfred Koizar <mkoi-pg@aon.at>)
Re: Suggestion for aggregate function  (Greg Stark <gsstark@mit.edu>)
List pgsql-hackers
Manfred Koizar <mkoi-pg@aon.at> writes:

> Greg, we already have this feature, just the syntax is a bit different :-)
> 
>        SELECT DISTINCT ON (item_id) item_id,
>               price AS lowest_price, 
>               store_id AS lowest_price_store
>          FROM items_for_sale
>         WHERE item_category = ?
>         ORDER BY item_id, price

Neat! I hadn't seen this. I would have liked to have had that feature on
Oracle! (Please don't tell me I did, I went through such pains to work around
not having it.)

Would this query be efficient if there's an index on item_id, price ? That is,
would it know to do an index scan and be able to skip to the next item_id in
the index as soon as a price was found?

-- 
greg



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Suggestion for aggregate function
Next
From: Jochem van Dieten
Date:
Subject: Re: Win32 port (native)