Reference card

Q is bigger than it looks: tokens play different roles, according to context. Here is a complete guide.

Reserved words

Aabs, acos, aj, aj0, all, and, any, asc, asin, asof, atan, attr, avg, avgs
Bbin, binr
Cceiling, cols, cor, cos, count, cov, cross, csv, cut
Ddelete, deltas, desc, dev, differ, distinct, div, do, dsave
Eeach, ej, ema, enlist, eval, except, exec, exit, exp
Ffby, fills, first, fkeys, flip, floor
Gget, getenv, group, gtime
Hhclose, hcount, hdel, hopen, hsym
Iiasc, idesc, if, ij, in, insert, inter, inv
Kkey, keys
Llast, like, lj, ljf, load, log, lower, lsq, ltime, ltrim
Mmavg, max, maxs, mcount, md5, mdev, med, meta, min, mins, mmax, mmin, mmu, mod, msum
Nneg, next, not, null
Oor, over
Pparse, peach, pj, prd, prds, prev, prior
Rrand, rank, ratios, raze, read0, read1, reciprocal, reval, reverse, rload, rotate, rsave, rtrim
Ssave, scan, scov, sdev, select, set, setenv, show, signum, sin, sqrt, ss, ssr, string, sublist, sum, sums, sv decode, sv consolidate, svar, system
Ttables, tan, til, trim, type
Uuj, ungroup, union, update, upper, upsert
Vvalue, var, view, views, vs encode, vs split
Wwavg, where, while, within, wj, wj1, wsum
Xxasc, xbar, xcol, xcols, xdesc, xexp, xgroup, xkey, xlog, xprev, xrank



glyphs use
() precedence; list definition; table definition
[] expression block; arguments; table definition
{} function definition (lambda)
; separator
` symbol
`: filepath


Overloaded glyphs

The following glyphs represent operators, functions or adverbs – according to context.

Other uses of /

  • in a session or script, preceded by a space, begins a trailing comment
  • in a script, followed by a newline, begins a multiline comment

Other roles of \

  • as a command in the debugger, aborts evaluation and returns to the q session
  • as a command in the session, \ toggles between the q and k parsers
  • as punctuation in a script, ends a multi-line comment
  • as punctuation in a script, (on a line by itself) marks the end of executable program



0:prepare-text, save-text, load-csv, load-fixed, parse-kv
1:read-binary, save-binary
2:dynamic load
0write to console
1 -1write to stdout
2 -2write to stderr
n, -nwrite to handle


Watch out

All single-letter namespaces (upper- and lower-case) are reserved for Kx use and should not be used to contain user-written code or data.

.h namespace, .Q namespace


Command-line options and system commands

See summaries of command-line options and system commands.

cmd/opt cmd/opt
\a tables -b blocked
\b \B views \c -c console size
-C \C HTTP size \cd change directory
\d directory \e -e error traps
\f functions \g -g garbage collection
\l load file or directory -l -L log sync
\o -o UTC offset \p -p multithread port
\P -P display precision -q quiet mode
\r -r replicate \r rename
\s -s slaves \S random seed
\t -t timer ticks \ts time and space
\T -T timeout \u -u -U usr-pwd
-u disable syscmds \v variables
\w -w memory \W -W week offset
\x expunge \z -z date format
\1 & \2 redirect \_ hide q code
\ terminate \ toggle q/k
\\ quit OS Commands
system file


char size num literal null name sql java .net
b 1 1 0b boolean Boolean boolean
g 16 2 0Ng guid UUID GUID
x 1 4 0x00 byte Byte byte
h 2 5 0h 0Nh short smallint Short int16
i 4 6 0i 0Ni int int Integer int32
j 8 7 0j / 0 0Nj / 0N long bigint Long int64
e 4 8 0e 0Ne real real Float single
f 8 9 0.0 or 0f 0n float float Double double
c 1 10 " " " " char Character char
s . 11 ` ` symbol varchar String string
p 8 12 dateDtimespan 0Np timestamp Timestamp DateTime (r/w)
m 4 13 2000.01m 0Nm month
d 4 14 2000.01.01 0Nd date date Date
z 8 15 dateTtime 0Nz datetime timestamp Timestamp DateTime (read only)
n 8 16 00:00:00.000000000 0Nn timespan Timespan TimeSpan
u 4 17 00:00 0Nu minute
v 4 18 00:00:00 0Nv second
t 4 19 00:00:00.000 0Nt time time Time TimeSpan

Nested types are 77+t (e.g. 78 is boolean. 96 is time.)

Cast char$data:CHAR$string

Int, float, char, symbol, literal nulls: 0N 0n " ", `.
Rest use type extensions, e.g. 0Nd. No boolean or byte nulls.

Infinite dates, times, datetimes: 0Wd 0Wz 0Wt (No math.)

date.(year month week mm dd)
table:([]x:…;y:…) or +`x`y!…
time.(minute second mm ss)
milliseconds: time mod 1000