Kdb+ provides a large number of data types, below is shown how to convert between types:

kdb+ Data Types

For reference the kdb+ data types table is reproduced on this page:

type size char num notation Null Value Positive Infinity
Mixed List0
boolean1b11b0b
byte1x40x260x00
short2h542h0Nh0Wh
int4i6420N0W
long8j742j0Nj0Wj
real4e84.2e0Ne0We
float8f94.20n0w
char1c10"z"" "
symbols11`zaphod`
timestamp8p122011.07.08D21:48:48.7031250000Np0Wp
month4m132006.07m0Nm0Wm
date4d142006.07.210Nd0Wd
datetime4z152006.07.21T09:13:390Nz0Wz
timespan8n160D21:56:26.4218750000Nn0Wn
minute4u1712:110Nu0Wu
second4v1812:11:170Nv0Wv
time4t1909:01:02:0420Nt0Wt
enum4*20-77`u$v
table98([] c1:ab`c; c2:10 20 30)
dictionary99`a`b`c!!10 20 30

Casting Types

Casting in kdb+ allows converting from one builtin type to another. Casting uses the $ symbol and specifies the type on the left and those values to be converted on the right. There are three variations for specifying castings and specifying the type to be converted to, using:

  1. Name.
  2. Lower Case Character.
  3. Type Number.
These values an be found in the columns "Type", "char" and "num" respectively in the Data Types table shown above. Here are some examples where we convert longs / shorts / floats to the integer type:

Casting Booleans, Chars...

When casting to some types the behaviour may not be intuitive, some rules to take note of are:

  • When casting to boolean, Zero/0 is false, everything else is true.
  • When casting from complex types (dates, characters, time..) to numeric values, the numeric value is simply the underlying value of the bytes.
    • Dates are stored as the number of days since 1st January 2000, casting to int returns that value.
    • Times are stored as the number of milliseconds since midnight, casting to int returns that value.
    • Characters are stored as UTF-8, casting returns the underlying UTF-8/ASCII value.

Cast Time to Hours, Minutes

A common use of casting is when performing aggregations, often we will want to bucket data stored with millisecond accurate timestamps by minute or second for example: To get the avg price each minute.

Casting Lists

Casting a list of values can be carried out in two ways. By either specifying the same type for all items or specifying a specific type for each item, this behaviour is identical to applying most dyadic functions to a list.

Parsing from Strings

Parsing is the term used for reading strings and converting them to other types. There is only one method of specifying parsing, using the uppercase letter together with the dollar $ operator. If a string is invalid and can't be interpreted as a given type, this will not throw an error, instead the value will be interpreted as null. Parsing a list of strings behaves similar to casting, you can specify one type to use for all parsing or specify individually for each item.


As shown above, casting and parsing in kdb+ is extremely easy.

  • Casting is mainly used for storing down values as the most suitable type.
  • Parsing is used when loading data into kdb+ from file.