reordering columns 'length error during xcols - Kdb+ / qStudio

Home Forums Kdb+ / qStudio reordering columns 'length error during xcols

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  admin 6 years, 5 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #164

    Bob

    When I try to reorder a table using xcols it is giving a ‘length error.


    q)`size`price xcols UKTradeTable
    k){(x,f@&~(f:cols y)in x)#y}
    'length
    #
    `size`price`date`time`sym
    (+`date`time!(`s#2013.03.23 2013.03.23 2013.03.23 2013.03.23 2013.03.23 2013.03.23 2013.03.23 2013.03.23 201.
    q.q))\
    q)cols UKTradeTable
    `date`time`sym`size`price
    q)select date,time,sym,price,size from UKTradeTable
    date time sym price size
    -----------------------------------------
    2013.03.23 09:00:00.026 HG 113.0829 624
    2013.03.23 09:00:00.055 KIL 169.8952 403
    2013.03.23 09:00:00.162 IUI 90.202 40
    ....

    #171

    admin
    Keymaster

    The length error with xcols is being caused by your table being keyed. There’s no real reason for this other than that xcols currently does not support keyed tables. You can use either ` xkey t or the shortcut 0!t to unkey the table and then use xcols. e.g.

    q)t:2!([] date:.z.d+til 3; time:3?.z.t; sym:`p`o`i; price:1 2 3.; size:100*1 2 3)
    q)t
    date time | sym price size
    -----------------------| --------------
    2013.04.02 05:19:46.499| p 1 100
    2013.04.03 08:06:26.022| o 2 200
    2013.04.04 05:40:18.945| i 3 300
    q)`size`price xcols t / reproduce same length error
    k){(x,f@&~(f:cols y)in x)#y}
    'length
    #
    `size`price`date`time`sym
    (+`date`time!(2013.04.02 2013.04.03 2013.04.04;05:19:46.499 08:06:26.022 05:4..
    q.q))\

    q)0!t
    date time sym price size
    --------------------------------------
    2013.04.02 05:19:46.499 p 1 100
    2013.04.03 08:06:26.022 o 2 200
    2013.04.04 05:40:18.945 i 3 300

    q)`size`price xcols 0!t
    size price date time sym
    --------------------------------------
    100 1 2013.04.02 05:19:46.499 p
    200 2 2013.04.03 08:06:26.022 o
    300 3 2013.04.04 05:40:18.945 i

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.