Skip to content

get, set

Read or set the value of a variable or a kdb+ data file


Read or memory-map a variable or kdb+ data file

get x     get[x]

Where x is

  • the name of a global variable as a symbol atom
  • a file or folder named as a symbol atom or vector

returns its value.

Signals a type error if the file is not a kdb+ data file.

Used to map columns of databases in and out of memory when querying splayed databases, and can be used to read q log files, etc.

q)get `a

q)\l trade.q
q)`:NewTrade set trade                  / save trade data to file
q)t:get`:NewTrade                       / t is a copy of the table
q)`:SNewTrade/ set .Q.en[`:.;trade]     / save splayed table
q)s:get`:SNewTrade/                     / s has columns mapped on demand
value is a synonym for get

By convention, value is used for other purposes. But the two are completely interchangeable.

q)value "2+3"
q)get "2+3"


Assign a value to a variable or file

x set y     set[x;y]

Where x is

  • a global variable named as a symbol atom
  • a file or folder named as a symbol atom

assigns the value of y to x.

q)`a set 1 2 3            / set name a
1 2 3

q)a set 1 2 3             / set name t (indirect assignment)
1 2 3

q)a set 1 2 3             / fails, as name must be a symbol

If x is a file symbol, the values are written to file.

q)`:work.dat set 1 2 3    / write values to file
q)get `:work.dat
1 2 3

Table to file

q)\l sp.q
q)`:mytable.dat set sp
q)get `:mytable.dat
s  p  qty
s1 p1 300
s1 p2 200
s1 p3 400

Table to directory

To save a table y splayed across a directory x

  • x must be a path that ends with a /
  • y must have no primary keys
  • columns of y must be vectors or compound lists
  • symbol columns in y must be fully enumerated
q)`:mydata/ set sp
q)\ls mydata
q)get `:mydata
s  p  qty
s1 p1 300
s1 p2 200
s1 p3 400


set saves the data in a binary format akin to tag+value, retaining the structure of the data in addition to its value.

q)`:data/foo set 10 20 30
q)read0 `:data/foo
"\376 \007\000\000\000\000\000\003\000\000\000\000\000\000\000"
Avoid setting variables in the Kx namespaces, as undesired and confusing behavior can result.

These are .h, .j, .Q, .q, .z, and any other namespaces with single-character names.

eval, value
File system