# Datatypes

The datatype of an object is given as a short int.

q)type 5                      / integer atom
-6h
q)type 2 3 5                  / integer list
6h
q)type (2;3 5f;"hello")       / mixed list
0h
q)type each (2;3 5f;"hello")
-6 9 10h
q)type (+)                    /not just data
102h


## Primitive datatypes¶

Primitive datatypes are in the range ± 1h to 19h: positive for a vector, negative for an atom. (A general list has type 0h.)
type

ncnameszliteralnullSQLJava.Net
0*list
1bboolean10bBooleanboolean
2gguid160NgUUIDGUID
4xbyte10x00Bytebyte
5hshort20h0NhsmallintShortint16
6iint40i0NiintIntegerint32
7jlong80j or 00Nj or 0NbigintLongint64
8ereal40e0NerealFloatsingle
9ffloat80.0 or 0f0nfloatDoubledouble
10cchar1" "" "Characterchar
11ssymbol.varcharStringstring
12ptimestamp8dateDtimespan0NpTimestampDateTime (RW)
13mmonth42000.01m0Nm
14ddate42000.01.010NddateDate
15zdatetime8dateTtime0NztimestampTimestampDateTime (RO)
16ntimespan800:00:00.0000000000NnTimespanTimeSpan
17uminute400:000Nu
18vsecond400:00:000Nv
19ttime400:00:00.0000NttimeTimeTimeSpan
20-76enums
77(unused)
78-9677+t – mapped list of lists of type t
97nested sym enum
98table
99dictionary
100lambda
101unary primitive
102operator
104projection
105composition
106f'
107f/
108f\
109f':
110f/:
111f\:

n: short int returned by type
c: character used for casting and load-csv
sz: size in bytes

Strings

There is no string datatype. The nearest equivalent to a string is a symbol, or a char vector. On this site, string is a synonym for character vector.

### Symbols¶

A back tick  followed by a series of characters represents a symbol, which is not the same as a string.

q)symbol ~ "symbol"
0b


A back tick without characters after it represents the empty symbol: .

Cast string to symbol

The empty symbol can be used with cast to cast a string into a symbol, creating symbols whose names could not otherwise be written, such as symbols containing spaces. $x is shorthand for "S"$x.


q)s:hello world
'world
9.223372e+18
q)float$0Wi 2.147484e+09  Arithmetic for float infinities (0we,0w) behaves as expected. q)0we + 5 0we q)0w + 5 0w  .Q.M (long infinity) ### Guid¶ The guid type (since V3.0) is a 16-byte type, and can be used for storing arbitrary 16-byte values, typically transaction IDs. Generation Use deal to generate a guid (global unique: uses .z.a .z.i .z.p).  q)-2?0Ng 337714f8-3d76-f283-cdc1-33ca89be59e9 0a369037-75d3-b24d-6721-5a1d44d4bed5  If necessary, manipulate the bytes to make the uuid a Version-4 'standard' uuid. Guids can also be created from strings or byte vectors, using sv or "G"$, e.g.


q)0x0 sv 16?0xff
8c680a01-5a49-5aab-5a65-d4bfddb6a661
q)"G"$"8c680a01-5a49-5aab-5a65-d4bfddb6a661" 8c680a01-5a49-5aab-5a65-d4bfddb6a661  0Ng is null guid. q)0Ng 00000000-0000-0000-0000-000000000000 q)null 0Ng 1b  There is no literal entry for a guid, it has no conversions, and the only scalar primitives are =, < and > (similar to sym). In general, since V3.0, there should be no need for char vectors for IDs. IDs should be int, sym or guid. Guids are faster (much faster for =) than the 16-byte char vecs and take 2.5 times less storage (16 per instead of 40 per). ## Other types¶ ### Enumerated types¶ Enumerated types are numbered from 20h up to 76h. For example, in a new session with no enumerations defined: q)type sym$10?sym:AAPLAIGGOOGIBM
20h
q)type city$10?city:londonparisrome 21h  (Since V3.0, type 20h is reserved for sym$.)

### Nested types¶

These types are used for mapped lists of lists of the same type. The numbering is 77 + primitive type (e.g. 78 is boolean, 96 is time and 97 is sym\$ enumeration.)

q):t1.dat set 2 3#til 6
:t1.dat
q)a:get :t1.dat
q)type a            /integer nested type
83h
q)a
0 1 2
3 4 5


### Dictionary and table¶

Dictionary is 99h and table is 98h.

q)type d:abc!(1 2;3 5;7 11)     / dict
99h
q)type flip d                      / table
98h


q)type each({x+y};neg;-;\;+[;1];<>;,';+/;+\;prev;+/:;+\:;f 2:f,1)
`