kdb+ select columns names as variables - Kdb+ / qStudio

Home Forums Kdb+ / qStudio kdb+ select columns names as variables

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #428

    Oskar Morgenstern
    Guest

    Hello,

    Is there a way to programmatically specify column names as variables in a select statement to kdb?

    Many Thanks.

    #496

    kdb+ allows functional queries
    http://www.timestored.com/kdb-guides/functional-queries-dynamic-sql

    e.g.

    q)t:([] a:1 2 3; b:4 5 6; c:7 8 9)
    q)colNames:`a`c
    q){?[t;();0b;x!x]} colNames
    a c

    1 7
    2 8
    3 9
    q){?[t;();0b;x!x]} `b`c
    b c

    4 7
    5 8
    6 9

    #40284

    Or you can mangle strings together and use eval:

    q)f:{value “select “,(“,” sv string x),” from t”}
    q)t:([] q:til 9; w:til 9; e:9?9)
    q)t
    q w e
    —–
    0 0 4
    1 1 2
    2 2 7
    3 3 0
    4 4 1
    5 5 2
    6 6 1
    7 7 8
    8 8 8
    q)f:{value “select “,(“,” sv string x),” from t”}
    q)f[`q`e]
    q e

    0 4
    1 2
    2 7
    3 0
    4 1
    5 2
    6 1
    7 8
    8 8
    q)

    • This reply was modified 10 years, 2 months ago by John Dempster.
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘kdb+ select columns names as variables’ is closed to new replies.