Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-04-02 Thread Decibel!
On Mar 25, 2008, at 11:33 AM, Sam Mason wrote: On Mon, Mar 24, 2008 at 05:27:04PM -0500, Decibel! wrote: On Mar 20, 2008, at 2:23 PM, Sam Mason wrote: SELECT i, (MIN((j,k))).k FROM tbl GROUP BY i; How is that any better than SELECT i, min(k) FROM tbl GROUP BY i ? Because I want the

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Decibel!
On Mar 20, 2008, at 2:23 PM, Sam Mason wrote: I'm trying to write a version of the MIN aggregate for values of RECORD type. I'm somewhat stuck on getting type information about the argument out, I can determine how many attributes it's got but I can't seem to do any better than that. Does

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Sam Mason
On Mon, Mar 24, 2008 at 05:27:04PM -0500, Decibel! wrote: On Mar 20, 2008, at 2:23 PM, Sam Mason wrote: SELECT i, (MIN((j,k))).k FROM tbl GROUP BY i; How is that any better than SELECT i, min(k) FROM tbl GROUP BY i ? Because I want the value of k associated with the minimum value of

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Gregory Stark
Sam Mason [EMAIL PROTECTED] writes: On Mon, Mar 24, 2008 at 05:27:04PM -0500, Decibel! wrote: On Mar 20, 2008, at 2:23 PM, Sam Mason wrote: SELECT i, (MIN((j,k))).k FROM tbl GROUP BY i; How is that any better than SELECT i, min(k) FROM tbl GROUP BY i ? Because I want the value of

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Sam Mason
On Mar 25, 2008, at 4:43PM, Gregory Stark wrote: On Mar 20, 2008, at 2:23 PM, Sam Mason wrote: SELECT i, (MIN((j,k))).k FROM tbl GROUP BY i; I have nothing against having min(record) and it does seem like it would let you do this at least for reasonably simple cases. The main reason

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Gregory Stark
Sam Mason [EMAIL PROTECTED] writes: SELECT i, MIN(k) OVER (PARTITION BY j) FROM tbl GROUP BY i; This is obviously wrong, but I don't see how to get to where I need to be. I'm not entirely sure myself. I think it might involve RANK OVER j though. I suspect it will look more like the

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Sam Mason
On Tue, Mar 25, 2008 at 06:58:06PM +, Gregory Stark wrote: Sam Mason [EMAIL PROTECTED] writes: SELECT i, MIN(k) OVER (PARTITION BY j) FROM tbl GROUP BY i; This is obviously wrong, but I don't see how to get to where I need to be. I'm not entirely sure myself. I think it

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Gregory Stark
Sam Mason [EMAIL PROTECTED] writes: On Tue, Mar 25, 2008 at 06:58:06PM +, Gregory Stark wrote: The main thing I wanted to avoid was an explosion of sub-queries that you get with DISTINCT ON style queries. For example, with record style syntax, I can do: SELECT i, (MIN((j,k))).k AS

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Sam Mason
On Tue, Mar 25, 2008 at 07:54:17PM +, Gregory Stark wrote: Sam Mason [EMAIL PROTECTED] writes: SELECT i, (MIN((j,k))).k AS ka, (MIN((mycode(j),k))).k AS kb FROM tbl GROUP BY i; The flip side is that if you want to get several fields based on min(j) the min(record) approach requires

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Gregory Stark
Sam Mason [EMAIL PROTECTED] writes: The reason for the sub-select is only because SQL doesn't provide any other way to name expressions. Hum, or at least this should work... There doesn't seem to be any nice way of getting fields out of a record! If I really want to do this, it's going to

Re: [HACKERS] writing a MIN(RECORD) aggregate

2008-03-25 Thread Sam Mason
On Wed, Mar 26, 2008 at 01:03:18AM +, Gregory Stark wrote: Sam Mason [EMAIL PROTECTED] writes: The reason for the sub-select is only because SQL doesn't provide any other way to name expressions. Hum, or at least this should work... There doesn't seem to be any nice way of getting

[HACKERS] writing a MIN(RECORD) aggregate

2008-03-20 Thread Sam Mason
Hi, I'm trying to write a version of the MIN aggregate for values of RECORD type. I'm somewhat stuck on getting type information about the argument out, I can determine how many attributes it's got but I can't seem to do any better than that. Does anyone have any good pointers into the code for