Core Concepts

Types

The q type system — atoms, vectors, mixed lists, nulls, infinities, and type casting.

Overview

Every q value has a type, and type tells you what it is as a short integer. The rule to remember:

  • An atom (a single value) has a negative type.
  • A simple list of atoms of that type has the same number, positive.
  • A mixed list has type 0h.
type 42          / -7h — a long atom
type 42 43       / 7h  — a list of longs
type "a"         / -10h — a char atom
type "ab"        / 10h  — a string is a list of chars
type `a          / -11h — a symbol atom
type (1;2.0)     / 0h   — a mixed list

The Basic Types

TypeNumberCharSize (bytes)ExampleNull
boolean1b11bnone
guid2g16-2?0Ng0Ng
byte4x10x2anone
short5h242h0Nh
int6i442i0Ni
long7j8420N
real8e43.14e0Ne
float9f83.140n
char10c1"a"" "
symbol11s—`AAPL`
timestamp12p82026.10.11D09:30:00.0000000000Np
month13m42026.10m0Nm
date14d42026.10.110Nd
datetime15z82026.10.11T09:30:00.0000Nz
timespan16n80D09:30:00.0000000000Nn
minute17u409:300Nu
second18v409:30:000Nv
time19t409:30:00.0000Nt

Some points that trip up newcomers:

  • A whole number is a long. 42 is a long (8 bytes). Write 42i for an int or 42h for a short.
  • A decimal number is a float. 3.14 is a float (8 bytes).
  • Strings are not atoms. "AAPL" is a list of 4 chars. A symbol such as `AAPL is a single atom, and is the usual choice for names and identifiers such as tickers and exchange codes. Use strings for free text that is rarely compared.
  • Datetime is deprecated. KX recommends timestamp instead.

The one-letter type chars in the table are used for casting and parsing (below), and in the t column of meta for a table.

Temporal Types

Dates, times and timestamps are stored as numbers counted from midnight on 2000.01.01. For example, a date is a count of days and a timestamp a count of nanoseconds. So you can do arithmetic on them:

2026.10.11+1                                        / 2026.10.12
2026.10.11-2026.01.01                               / 283i — days between two dates
2026.10.11D09:30:00 - 2026.10.11D09:00:00           / 0D00:30:00.000000000
`int$2026.01.01                                     / 9497i — days since 2000.01.01

Casting extracts parts of a temporal value:

`date$2026.10.11D09:30:00                           / 2026.10.11
`month$2026.10.11                                   / 2026.10m
`year$2026.10.11                                    / 2026i
`minute$09:30:15                                    / 09:30

.z.p is the current timestamp in UTC, and .z.d the current date in UTC. .z.P and .z.D give local time.

Nulls and Infinities

Most types have a null, a value meaning "missing". null tests for it:

null 0N             / 1b
null each (1;0n;`;`a)    / 0110b

Numeric types also have infinities: 0W and -0W for long, and 0w and -0w for float.

Nulls behave like ordinary values in arithmetic. Integer overflow does not signal an error; for an int, it lands on null:

0N+1                 / 0N
2147483647i+1i       / 0Ni — the largest int plus 1

A long null is smaller than every other long, including -0W:

0N < -0W    / 1b

The boolean and byte types have no null. Their zero values 0b and 0x00 are just ordinary values.

Casting

Cast between types with $. The left argument is the target type, given as a symbol name or as the type char:

`long$2.4 2.6    / 2 3 — rounds to the nearest whole number
`float$3         / 3f
"j"$"a"          / 97 — a char's ASCII code
`$"AAPL"         / `AAPL — string to symbol

string goes the other way, from any value to a string:

string `AAPL     / "AAPL"
string 42        / "42"

Parsing Strings

To parse text (read the value written in a string), use an upper-case type char:

"J"$"42"            / 42
"F"$"3.14"          / 3.14
"D"$"2026.10.11"    / 2026.10.11
"J"$("1";"22";"x")  / 1 22 0N — text that doesn't parse gives null

Note the difference: "j"$"4" casts the char to its code, 52, while "J"$"4" parses the text, giving 4.

Arithmetic and Types

Arithmetic widens to the larger type:

type 1+1h     / -7h — short plus long is a long
3%2           / 1.5 — % (divide) always returns a float
7 div 2       / 3   — integer division
7 mod 2       / 1

Mixing types where it makes no sense signals 'type. For example, 1+`a tries to add a number to a symbol.