[Fwd: [Fwd: Re: [GENERAL] return MAX and when it happened]]

2008-11-24 Thread Scara Maccai
I don't understand: is my question not clear, stupid, or you guys just don't like me? ;) Original Message Subject:[Fwd: Re: [GENERAL] return MAX and when it happened] Date: Fri, 21 Nov 2008 08:48:44 -0600 From: Scara Maccai <[EMAIL PROTECTED]> To

[Fwd: Re: [GENERAL] return MAX and when it happened]

2008-11-21 Thread Scara Maccai
Can someone answer me? Or do I have to ask this in the hackers list? I don't get from the docs: do I have to call get_call_result_type(fcinfo, NULL, &tupdesc) every time? I mean: the only example I've found about returning Composite Types talks about returning sets as well (34.9.10. Returni

Re: [GENERAL] return MAX and when it happened

2008-11-20 Thread Scara Maccai
Sam Mason wrote: On Wed, Nov 19, 2008 at 05:06:14PM -0600, Scara Maccai wrote: I think I wrote it, but there's something I don't get from the docs: do I have to call get_call_result_type(fcinfo, NULL, &tupdesc) I've always tried to stay away from C level extensions so far! How many

Re: [GENERAL] return MAX and when it happened

2008-11-20 Thread Sam Mason
On Wed, Nov 19, 2008 at 05:06:14PM -0600, Scara Maccai wrote: > Sam Mason wrote: > >The custom aggregate sounds the > >most elegant, it's just annoying that it's so much fiddling to get it > >all working to start with > Thanks. > > I think I wrote it, but there's something I don't get from the doc

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Scara Maccai
Sam Mason wrote: The custom aggregate sounds the most elegant, it's just annoying that it's so much fiddling to get it all working to start with Thanks. I think I wrote it, but there's something I don't get from the docs: do I have to call get_call_result_type(fcinfo, NULL, &tupdesc) every

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Sam Mason
On Wed, Nov 19, 2008 at 10:10:08AM -0600, Scara Maccai wrote: > Sam Mason wrote: > >Do you really want the SUM of num1 and num2, because that makes it more > >fiddly and would be where having MAX accept a record/tuple would be > >best. If you don't, maybe something like: > > > > SELECT DISTINCT O

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Scara Maccai
Sam Mason wrote: Do you really want the SUM of num1 and num2, because that makes it more fiddly and would be where having MAX accept a record/tuple would be best. If you don't, maybe something like: SELECT DISTINCT ON (date_trunc('day', mydate)) date_trunc('day', mydate), num, num1+num2

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Sam Mason
On Wed, Nov 19, 2008 at 09:35:34AM -0600, Scara Maccai wrote: > Well you guys are right; the problem is that the query is actually more > complex, I tried to simplify it for the question, but ended up with a > trivial question... always a problem with simplification, I've done the same far too o

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Scara Maccai
Sam Mason wrote: Why not just do: SELECT * FROM mytab ORDER BY num, mydate LIMIT 1; If you're trying to do more complicated things, DISTINCT ON may be more useful. Well you guys are right; the problem is that the query is actually more complex, I tried to simplify it for the questio

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Sam Mason
On Wed, Nov 19, 2008 at 08:47:57AM -0600, Scara Maccai wrote: > CREATE TABLE mytab > ( > num integer, > mydate timestamp > ); > > and I want to find MAX(num) and the "mydate" where it first happened. > > I guess I could use > > select * from mytab where num = (select MAX(num) from mytab)

Re: [GENERAL] return MAX and when it happened

2008-11-19 Thread Csaba Nagy
Hi Scara, This should work just fine: select num, min(mydate) from mytab group by num order by num desc limit 1; If you have an index on 'num' it will also be fast. Cheers, Csaba. On Wed, 2008-11-19 at 08:47 -0600, Scara Maccai wrote: > Hi all, > > suppose I have a table like: > > CREATE TAB

[GENERAL] return MAX and when it happened

2008-11-19 Thread Scara Maccai
Hi all, suppose I have a table like: CREATE TABLE mytab ( num integer, mydate timestamp ); and I want to find MAX(num) and the "mydate" where it first happened. I guess I could use select * from mytab where num = (select MAX(num) from mytab) order by mydate limit 1; but that would sc