Reference card

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 (purge), .Q.res (reserved words)


f each xeachapply f to each item of x
x f'yeach-bothapply f between items of x and y
x f\:yeach-leftapply f between y and items of x
x f/:yeach-rightapply f between x and items of y
f':xeach-parallelapply f to items of x in parallel tasks
f peach xpeachapply f to items of x in parallel tasks
f':xeach-priorapply f between successive pairs of items of x
f prior xpriorapply f between successive pairs of items of x
x f/yrepeatapply f to y, x times
{x} f/yoverreduce y with f
f over xoverapplies f between successive items of x
f/[x;y;…]foldreduce [x;y;…] with f
f\xconvergeapply f to x until converges
x f\yiterateapply f to y, x times or while x
f\xscanapply f/ to successive items of x
f scan xscanapply f/ to successive items of x
do[x;e1;e2;e3;…;en]doevaluate e1 to en, x times
while[t;e1;e2;e3;…;en]whileevaluate e1 to en until t is false

Adverbs, Evaluation control



()precedence; list definition; table definition
[]expression block; arguments; table definition
{}function definition (lambda)


=equal<>not equal~match
<less than<=less than or equal>greater than>=greater than or equal
+plus-minus*times%divided by
#take,join^fill, coalesce_drop; cut
|maximum, or&minimum, and


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

'casesignalcompose, each-both
?find, roll, deal, enum-extendvector conditional, exec, select
!dict, key, enumerate , ints to enumupdate, delete
$cast, tok, enum, pad, product, mmucond
\:int to byteeach-left
':each-parallel, each-prior
/(see note below)converge-repeat, over, fold
\(see note below)converge-iterate, scan

Other roles 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


::null, identity
csvcomma as record delimiter


`s#2 2 3sorted0
`u#2 4 5unique16*u
`p#2 2 1parted(4*u;16*u;4*u+1)
`g#2 1 2grouped(4*u;16*u;4*u+1;4*n)



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

Command-line options and system commands

\b \Bviews\c -cconsole size
-C \CHTTP size\cdchange directory
\ddirectory\e -eerror traps
\ffunctions\g -ggarbage collection
\lload file or directory-l -Llog sync
\o -oUTC offset\p -pmultithread port
\P -Pdisplay precision-qquiet mode
\r -rreplicate\rrename
\s -sslaves\Srandom seed
\t -ttimer ticks\tstime and space
\T -Ttimeout\u -u -Uusr-pwd
-udisable syscmds\vvariables
\w -wmemory\W -Wweek offset
\xexpunge\z -zdate format
\1 & \2redirect\_hide q code
\terminate\toggle q/k
\\quitOS Commands

command-line options, system commands

Environment variables

QHOME$HOME/qfolder searched for q.k and unqualified script names
QLIC$HOMEfolder searched for k4.lic license file
QINITq.qadditional file loaded after q.k has initialised
LINESsupplied by OS, used to set \c

Ensure LINES and COLUMNS are exported. In Bash

before starting q.


j870j or 00Nj or 0NlongbigintLongint64
f890.0 or 0f0nfloatfloatDoubledouble
c110" "" "charCharacterchar
p812dateDtimespan0NptimestampTimestampDateTime (r/w)
z815dateTtime0NzdatetimetimestampTimestampDateTime (read only)

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



.z.aIP address.z.acHTTP auth from cookie
.z.bdependencies.z.bmmsg validator
.z.ccores.z.eTLS connection status
.z.exitaction on exit.z.ffile
.z.krelease date.z.Kversion
.z.llicense.z.nUTC timespan
.z.Nlocal timespan.z.oOS version
.z.pUTC timestamp.z.Plocal timestamp
.z.pcclose.z.pdpeach handles
.z.pgget.z.phHTTP get
.z.piinput.z.pmHTTP options
.z.poopen.z.ppHTTP post
.z.psset.z.pwvalidate user
.z.qquiet mode.z.sself
.z.tstimer.z.uuser ID
.z.vsvalue set.z.whandle
.z.Whandles.z.wcwebsocket close
.z.wowebsocket open.z.wswebsockets
.z.xargv.z.Xraw command line
.z.zUTC datetime.z.Zlocal datetime
.z.zdzip defaults
.z.t, .z.T, .z.d, .z.Dtime/date shortcuts


.h.brlinebreak.h.c0web color
.h.c1web color.h.cdCSV from data
.h.edExcel from data.h.edsn
.h.hbanchor target.h.hcescape lt
.h.heHTTP 400.h.hnHTTP error
.h.hpHTTP response.h.hrhorizontal rule
.h.htMarqdown to HTML .h.htastart tag
.h.huURI escape.h.hugURI map
.h.hyHTTP response.h.iso8601ISO timestamp
.h.jxtable.h.logoKx logo
.h.nbrno break.h.prepre
.h.tyMIME types.h.uhURI unescape
.h.xsXML escape.h.xtJSON


.Q.addmonths.Q.addrIP address
.Q.bvbuild vp.Q.chkfill HDB
.Q.cncount partitioned table.Q.Dpartitions
.Q.ddjoin symbols.Q.def
.Q.dpftsave table.Q.dsftgload process save
.Q.enenumerate varchar cols.Q.fformat
.Q.fcparallel on cut .Q.ffappend columns
.Q.fkforeign key.Q.fmtformat
.Q.fpsstreaming algorithm.Q.fsstreaming algorithm
.Q.fsnstreaming algorithm.Q.ftapply simple
.Q.fuapply unique.Q.gcgarbage collect
.Q.hdpfsave tables.Q.hgHTTP get
.Q.hosthostname.Q.hpHTTP post
.Q.idpurge.Q.indpartitioned index
.Q.j10encode binhex .Q.j12encode base64
.Q.kversion .Q.lload
.Q.Mlong infinity.Q.MAPmaps partitions
.Q.optcommand parameters.Q.Psegments
.Q.parlocate partition.Q.pdmodified partition locations
.Q.PDpartition locations.Q.pfpartition type
.Q.pnpartition counts.Q.ptpartitioned tables
.Q.pvmodified partition values.Q.PVpartition values
.Q.qpis partitioned.Q.qtis table
.Q.resk words.Q.splain text
.Q.tytype.Q.udate based
.Q.Vtable to dict.Q.vvalue
.Q.viewsubview.Q.vpmissing partitions
.Q.wmemory stats.Q.x10decode binhex
.Q.x12decode base64 .Q.xnon-command parameters
.Q.Xfcreate file

Single-letter namespaces

All single-letter namespaces (upper- and lower-case) are reserved for Kx use. Do not use single-letter namespaces as containers for user-written code or data.