convert rows of a table to list

832 views
Skip to first unread message

Roy

unread,
Jan 19, 2017, 3:15:39 AM1/19/17
to Kdb+ Personal Developers
Hi,

Table t:

c1 c2 c3
-----------
`a 1 `x
`b 2 `y
`c 3 `z

How to convert rows to a list like this:
L:((`a;1;`x);(`b;2;`y);(`c;3;`z))

Thanks.

AquaQMatt

unread,
Jan 19, 2017, 5:10:37 AM1/19/17
to Kdb+ Personal Developers
Hi Roy, 

I think you're looking for something along the lines of this?

q)t
c1 c2 c3
--------
a  1  x
b  2  y
c  3  z

q)lists:{value t[x]} each til count t

q)lists
`a 1 `x
`b 2 `y
`c 3 `z

Regards,
Matt

ryan.m...@aquaq.co.uk

unread,
Jan 19, 2017, 5:10:37 AM1/19/17
to Kdb+ Personal Developers
Hi Roy,
A simple way to do this is with flip and value:
q)t:([]a:`a`b`c;b:1 2 3;c:`x`y`z)
q)t
a b c
-----
a 1 x
b 2 y
c 3 z
q)flip value flip t
`a 1 `x
`b 2 `y
`c 3 `z

So here, the first flip turns the table into a list of dictionaries, which can be valued to strip the keys, which is then flipped back to your preferred format.

Thanks,
Ryan

allan.mo...@gmail.com

unread,
Jan 19, 2017, 5:10:37 AM1/19/17
to Kdb+ Personal Developers
Hi Roy,

"value each t" should work in that case.

Thanks

Allan


On Thursday, January 19, 2017 at 8:15:39 AM UTC, Roy wrote:

RAHUL ASATI

unread,
Jan 19, 2017, 5:12:58 AM1/19/17
to Kdb+ Personal Developers
To convert simple table to list:

l:flip t cols t

rolf

unread,
Jan 24, 2017, 12:00:19 AM1/24/17
to personal...@googlegroups.com
t[;cols t]

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages