What are some of the hard limits of kdb I should know about?

  • no more than 2GB over IPC
  • number of tables mapped is limited by number of file descriptors allowed by OS
  • maximum of 32 global references per function
  • maximum of 23 local variables per function
  • maximum of 96 constants within a function
  • enums are limited to 57 - (type values 20h to 76h)
  • 4096 maximum compressed files open (for versions earlier than 3.1T2013.02.21)
  • 999 nested columns in splayed table
  • 1022 maximum incoming network connections
  • maximum of eight function parameters
  • maximum number of mapped nested columns 1024
  • maximum number of active `g# indices 1024
  • maximum branch (if; do; while; $[]) distance is 255 byte codes away (from PC to PC+255bytes!) - if you get a 'branch error, you have to break the code up into smaller pieces

See also: error codes

Is q a purely functional language?

No. Please see wikipedia entry on Purely functional and programming language family tree diagram (K is found toward the left, as a decendent of APL & Scheme.

Is function overloading supported in q?

Despite the fact that many native functions are overloaded, no. The last function definition simply overwrites the prior ones.

q)f: {[x]}
q)f: {[x; y]}
{[x; y]}

Why can’t I use exec on partitioned tables?

We don't know. We imagine that kx has something clever up their sleeve that hasn't been released yet. For now, just use exec select from tablename.

What's the difference between kdb, kdb+, k, k4 and q?

kdb is the predecessor to kdb+®.  At one point kdb was an application on top of k.   At kdbfaq, we refer to kdb+® as kdb. q is the programming language of kdb. It's a small layer of syntatic sugar on top of k, plus several significant extensions and new datatypes. k4 is simply an old name for q.

See $QHOME/q.k to see how much of q is written in k.

What does error output 'nyi mean?

'nyi means, "not yet implemented." Sometimes you see this error for expressions that are simply wrong. In any case, you need to try a different approach.

See also: kdb error code table

I know kdb is a in-memory database. my dataset is over two terabytes in size. However my RAM is limited to 32GB. How will this work?

Like any computer process, the maximum amount of data loaded into memory is limited by the real physical memory addressable by your process. On a 32-bit server, this can be little as 2GB. On a 64-bit server, 64TB is possible as of this writing, and that limit will continue to increase in the future.

However, with memory mapped tables, the size of your table can theoretically be as large as your disk (assuming it does not exceed the kdb limitations). As long as the operations you perform on your database don't require more than your RAM can handle at once, you'll be fine. That's how kdb has been handling multi-terabyte databases for years.

Can q script be compiled down to native code?

We are not aware of an available q-to-native-code compiler.

If your goal is to prevent clients from being able to read your code, see this related faq.

Is polymorphism supported in q?

While q has no notion of inheritance, class, metaclass, or prototype, you can create structures packaged with associated functions and invoke those functions via the structures. Consider the following tired OO example expressed in q:

Draw: {[shape] shape[`draw] shape}

(Sadly, we cannot write shape.draw shape; dot notation is not supported for local variables, including arguments.)

Given an appropriate set of constructors -

NewCircle: {[x; y; radius]
`x`y`radius`draw ! (x; y; radius; {[circle] … })}
NewRectangle: {[x; y; w; h]
`x`y`w`h`draw ! (x; y; w; h; {[rect] …})}

etc, the following does exactly what you would expect:

shapes: (NewCircle[0; 0; 1];
         NewRectangle[-1; -2; 4; 2]);
Draw each shapes;

How can I glue two tables side by side?

If the tables have the same number of rows, you can use the function ^ (fill):

q)t: ([] x: `a`b; y: 1 2)
q)u: ([] z: "YN")
q)t ^ u / works only when count[t] = count[u]
x y z
a 1 Y
b 2 N