Skip to content

Q language resources by topic

Casting and encoding

$ Cast between datatypes $ Tok: interpret string as value ! Enumeration parse parse string to function string cast to character sv decode to integer value parse string to function vs encode

Comparison

Precision

Dictionaries

! Dict make a dictionary key key list group group list by values value value list

Environment

variable defines default
COLUMNS \c 80
LINES \c 25
QHOME folder searched for q.k and unqualified script names $HOME/q
C:\q
QINIT additional file loaded after q.k has initialized,
executed in the default namespace
$QHOME/q.q
%QHOME%\q.q
QLIC folder searched for k4.lic or kc.lic license key file $QHOME
%QHOME%

getenv get value of an environment variable gtime UTC equivalent of local timestamp ltime local equivalent of UTC timestamp setenv set value of an environment variable

Evaluation control

File system

get set read/write or memory-map a data file¹ value read a data file¹

hcount file size hdel delete a file or folder hsym symbol/s to file symbol/s¹

0: File Text read/write chars¹ read0 read chars¹ 1: File Binary read/write bytes¹ read1 read bytes¹ 2: Dynamic Load load shared object

save load a variable rsave rload a splayed table dsave tables ? Enum Extend

¹ Has application beyond the file system.

Functional qSQL

![t;c;b;a]              / update and delete

?[t;i;p]                / simple exec

?[t;c;b;a]              / select or exec
?[t;c;b;a;n]            / select up to n records
?[t;c;b;a;n;(g;cn)]     / select up to n records sorted by g on cn

Interprocess communication

\p -p listen to port hopen hclose open/close connection .z callbacks

Joins

Keyed As of ej equi aj aj0 as-of ij ijf inner ajf ajf0 lj ljf left asof simple as-of pj plus wj wj1 window uj ujf union upsert , Join ^ Coalesce

Logic

all whether all items are non-zero & and lesser of two values; logical AND any whether any item is zero not whether if argument is zero null whether is null | or greater of two values; logical OR

Math and statistics

abs absolute value mins minimums acos arccosine mmax moving maximum asin arcsine mmin moving minimum atan arctangent mmu matrix multiply avg arithmetic mean mod modulo avgs arithmetic means msum moving sum ceiling round up to integer prd product cor correlation prds products cos cosine ratios ratios cov covariance reciprocal reciprocal deltas differences scov sample covariance dev standard deviation sdev sample standard deviation div integer division signum sign ema exponential moving average sin sine exp ex sqrt square root floor round down to integer sum sum inv matrix inverse sums sums log natural logarithm svar sample variance lsq matrix divide tan tangent mavg moving average til natural numbers till max greatest var variance maxs maximums wavg weighted average mcount moving count wsum weighted sum mdev moving deviation xbar round down med median xexp xy min least xlog base-x logarithm of y

QSQL query templates

delete delete rows or columns from a table exec return columns from a table, possibly with new columns select return part of a table, possibly with new columns update add rows or columns to a table

bin, binr binary search distinct unique items of a list ? Find find x in y in which items of x are items of y within whether x are items of list y

Selection

except exclude items of one list or dictionary from another first first item of a list or first entry of a dictionary . Index select item at depth from a list or entries from a dictionary @ Index At select items from a list or entries from a dictionary inter intersection of two lists or dictionaries last last item of a list or last entry of a dictionary next immediately following item/s prev immediately preceding item/s sublist sublist of a list union union of two lists or dictionaries where copies of indexes of a list, or keys or of a dictionary xprev nearby list items

Sort

asc sort ascending desc sort descending group group a list by values iasc grade ascending idesc grade descending rank position in sorted list xgroup group table by values of selected column/s xrank group by value xasc sort table ascending xdesc sort table descending

Duplicate dictionary keys or table column names cause unpredictable results from sorts, grades, and groups.

Re-sorting compressed data on disk decompresses it.

Dictionaries, Tables

Strings

$ Pad pad with spaces like match pattern lower shift to lower case ltrim trim leading space md5 hash from string rtrim trim trailing space ss string search ssr string search and replace trim trim leading and trailing space upper shift to upper case

Tables

cols column names ungroup normalize meta metadata xasc sort ascending xcol rename cols xdesc sort descending xcols re-order cols xgroup group by values in selected cols insert insert records xkey sset cols as primary keys upsert add/insert records xdesc sort descending ! Enkey, Unkey add/remove keys

qSQL query templates: select exec update delete

Back to top