Given a table t that has a date column d (d is a symbol; actuallythere are several such tables where the date column name varies, hencethe need to abstract over it) and the query “exec (min date;max date)from t”, what is its functional form?With just min the answer is easy enough: ?[t;();();(min;d)] but Ican’t find how to do both min and max: ?[t;();();((min;d);(max;d))]doesn’t work: type error, and I don’t find the output of parse veryhelpful in practice.
This seems to to the trick:q)parse"exec min date,max date from t"?t()()
datedate1!((min;
date);(max;date))q)?[t;();();
dmindmax!((min;
date);(max;`date))]dmin| 2009.01.01dmax| 2009.01.10On 1 Apr, 21:56, annakh7 <anna…> wrote:> Given a table t that has a date column d (d is a symbol; actually> there are several such tables where the date column name varies, hence> the need to abstract over it) and the query “exec (min date;max date)> from t”, what is its functional form?>> With just min the answer is easy enough: ?[t;();();(min;d)] but I> can’t find how to do both min and max: ?[t;();();((min;d);(max;d))]> doesn’t work: type error, and I don’t find the output of parse very> helpful in practice.</anna…>
Yes, that does the trick but it’s a bit different form what I amlooking for: I don’t want a dictionary or a table but a date pair.Still, one can take the value of this dictionary.
In the same vein one can also do: (min;max)@:?[pt;();();d] but againthat’s not the answer to the question. It frustrates me thatfunctional exec’s are so difficult to haruspicate.
> With just min the answer is easy enough: ?[t;();();(min;d)] but I> can’t find how to do both min and max: ?[t;();();((min;d);(max;d))]> doesn’t work: type error, and I don’t find the output of parse very> helpful in practice.q)?[t;();();(plist;(min;date);(max;
date))]2009.04.02 2009.04.02if a parse tree has an empty element (0 in"(;(min;date);(max;
date))"), it’s almost certainly plist
Thanks! I had indeed no idea what to put in the place of that emptyelement, hence my complaint that this is more haruspication thanprogramming. For the record, how did you find out?PS: plist is deprecated; the “modern” form is enlist
On Thu, Apr 2, 2009 at 7:46 AM, annakh7 wrote:> Thanks! I had indeed no idea what to put in the place of that empty> element, hence my complaint that this is more haruspication than> programming. For the record, how did you find out?experience, mostly. it can be verified thus:q)plist~(parse"exec(min date;max date)from t"). 4 0 01bor you could get a newer version of q–plist/enlist prints properly now$ qKDB+ 2.4 2008.10.30 Copyright (C) 1993-2008 Kx Systemsl64/ 4(8)core 32135MBq)parse"exec(min date;max date)from t"?t()(),(plist;(min;
date);(max;`date))haruspication is an awesome word btw
Indeed plist prints properly now. I wonder why they continue to use itwhile marking it as deprecated in the reference, though.