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 listThe Basic Types
| Type | Number | Char | Size (bytes) | Example | Null |
|---|---|---|---|---|---|
| boolean | 1 | b | 1 | 1b | none |
| guid | 2 | g | 16 | -2?0Ng | 0Ng |
| byte | 4 | x | 1 | 0x2a | none |
| short | 5 | h | 2 | 42h | 0Nh |
| int | 6 | i | 4 | 42i | 0Ni |
| long | 7 | j | 8 | 42 | 0N |
| real | 8 | e | 4 | 3.14e | 0Ne |
| float | 9 | f | 8 | 3.14 | 0n |
| char | 10 | c | 1 | "a" | " " |
| symbol | 11 | s | — | `AAPL | ` |
| timestamp | 12 | p | 8 | 2026.10.11D09:30:00.000000000 | 0Np |
| month | 13 | m | 4 | 2026.10m | 0Nm |
| date | 14 | d | 4 | 2026.10.11 | 0Nd |
| datetime | 15 | z | 8 | 2026.10.11T09:30:00.000 | 0Nz |
| timespan | 16 | n | 8 | 0D09:30:00.000000000 | 0Nn |
| minute | 17 | u | 4 | 09:30 | 0Nu |
| second | 18 | v | 4 | 09:30:00 | 0Nv |
| time | 19 | t | 4 | 09:30:00.000 | 0Nt |
Some points that trip up newcomers:
- A whole number is a long.
42is a long (8 bytes). Write42ifor an int or42hfor a short. - A decimal number is a float.
3.14is a float (8 bytes). - Strings are not atoms.
"AAPL"is a list of 4 chars. A symbol such as`AAPLis 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.01Casting 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) / 0110bNumeric 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 1A long null is smaller than every other long, including -0W:
0N < -0W / 1bThe 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 symbolstring 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 nullNote 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 / 1Mixing types where it makes no sense signals 'type. For example, 1+`a tries to add a number to a symbol.