rank error during select x y z from table - Kdb+ / qStudio

Home Forums Kdb+ / qStudio rank error during select x y z from table

Tagged: ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #242

    Johnny Chan
    Guest

    When I create a function to call a select I get a rank error, but when I do the same query outside a function it works. Is this a bug in kdb?

    q)f:{select from trade where (date in x),(sym in y)}
    q)f[2013.04.18 2013.04.19; `AB`CD]
    ‘rank

    select from trade where (date in 2013.04.18 2013.04.19),(sym in `AB`CD)

    Works and returns the data I expect.

    #260

    John Dempster
    Keymaster

    It is a bug. q has issues with default parameters and qsql queries inside function. You can see this from the code below:

    `q)t:([] a:1 2 3 4 5; b:6 7 8 9 0)
    q)t
    a b

    1 6
    2 7
    3 8
    4 9
    5 0`

    One parameter works
    `
    q){select from t where a in x}[2 3]
    a b

    2 7
    3 8`

    Two parameters fail.
    `
    q){select from t where a in x,b in y}[2 3;6 7]
    ‘rank
    `

    Notice when I name the parameters the function executes successfully.
    `
    q){[x;y] select from t where a in x,b in y}[2 3;6 7]
    a b

    2 7`

    I recommend specifying sensible names (not x/y) as much as possible.

    #506

    charlie
    Guest

    it’s not a bug and is documented on code.kx.com, local variables masked within select.

    #527

    John Dempster
    Keymaster

    Most programming languages follow the substitution principle that assigning a value to a variable, means anywhere that variable is used the user can consider it as if the value was directly entered in place. Breaking this common rule to allow simplification of the parser at the expense of user friendliness is not a choice many other languages have made.

     

    Because this is such uncommon and non-intuitive behavior for what is a common piece of code, I would call it a bug.

    #966

    charlie
    Guest

    John – a quick question – do you speak on behalf of Kx, or is this just your opinion? Thanks for clarifying.

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

You must be logged in to reply to this topic.