I just copied my study notes

Overview

Integer Data

Long

q)42
42
q)42j
42
Copy the code

Short 

q)-123h
-123h
Copy the code

Int

q)1234567890i
1234567890i
Copy the code

Floating Point Data

float

Q) f 1 f q) 1.234 e-7 e-07 1.234Copy the code

real

Q) 1.234 e7 e 12340000 eCopy the code

Floating Point Display

You can change this by using the \P command (note upper case) to specify a display width up to 16 digits. If you issue \P 0 the console will display all 17 decimal digits of the underlying binary representation, although the last digit is unreliable.

Q)f12:1.23456789012 Q)\P 12 q)f12 1.23456789012Copy the code

Binary Data

boolean

q)0b
0b
q)42+1b
43
Copy the code

byte

0x followed by two hexadecimal digits

q)1+0x29
42
Copy the code

GUID

q)2? 0Ng 2d948578-e9d6-79a2-8207-9df7a71f0b3b 409031f3-b19c-6770-ee84-6e9369c98697Copy the code

Text Data

char

q)"q"
"q"
q)"\\"
"\"
q)"\142"
"b"
Copy the code

symbol

A symbol is an atom holding text. It is denoted by a leading back-quote, read “back tick” in q-speak.

q)`q
`q
Copy the code

A symbol is akin to a SQL VARCHAR, in that it can hold an arbitrary number of characters, but is different in that it is atomic. The char "q" and the symbol `kdb are both atomic entities. A symbol is irreducible, meaning that the individual characters that comprise it are not directly accessible.

A symbol is not a string.

q)`a~"a"
0b
Copy the code

Temporal Data

date

Q)2015.01.01 2015.01.01 Q)2000.01.01=0 1b q)2000.01.02=1 1b q)1999.12.31=-1 1b q) 'int$2000.02.01 31iCopy the code

Time Types

There are two versions of time, depending on the resolution required. If milliseconds are sufficient, use the time type, which stores the count of milliseconds from midnight in a 32-bit signed integer. It is denoted by hh:mm:ss.uuu where hh represents hours on the 24-hour clock, mm represents minutes, ss represents seconds, and uuu represents milliseconds.

Q)12:34:56.789 12:34:56.789t q)12:00:00.000=12*60*60*1000 1b q) 'int$12:00:00.000 43200000iCopy the code

It is denoted by 0Dhh:mm:ss.nnnnnnnnn where hh represents hours on the 24-hour clock, mm represents minutes, ss represents seconds, and nnnnnnnnn represents nanoseconds. Observe that the leading 0D is optional.

Q)12:34:56.123456789 0d12:34:56.123456789 Q)12:34:56.123456 / microseconds become nanos 0d12:34:56.123456000Copy the code

Date-Time Types

A datetime (deprecated) is the lexical combination of a date and a time, separated by T as in the ISO standard format. A datetime value stores in a float the fractional day count from midnight Jan 1, 2000.

Q)2000.01.01T12:00:00.000 2000.01.01T12:00:00.000 Q) 'float$2000.01.02T12:00:00.000 1.5 Q) ` date $2000.01.02 T12:00:00) 000 2000.01.02 q) ` time $2000.01.02 T12:00:00. 000 12:00:00. 000Copy the code

The preferred type is timestamp, which is the lexical combination of a date and a timespan, separated by D. The underlying timestamp value is a long representing the count of nanoseconds since the millennium. Post-millennium is positive and pre- is negative.

Q) 2014.11.22 D17:43:40. 123456789 2014.11.22 D17:43:40. 123456789 q) ` timespan $2014.11.22 D17:43:40. 123456789 0 d17:43:40. 123456789Copy the code

month

Q)2015.11m 2015.11m q)2001.01m=12 1b q) 'int$2015.01m 180i q)2015.07m=2015.07.01 1bCopy the code

minute

Q)12:30 12:30 q)12:00=12*60 1b q) 'int$12:00 720i q)12:00=12:00:00.000 1bCopy the code

second

Q)23:59:59 23:59:59=-1+24*60*60 1b q)12:34:56=12:34:56.000 1BCopy the code

Constituents and Dot Notation

Q)dt:2014.01.01 q)dt.year 2014i q)dt.mm 1i q)dt.dd 1i q)ti:12:34:56.789 q)ti. Hh 12i q)ti. Mm 34i q)ti. Ss 56i q) 'month$dt 2014.01 M q)(' int$12:34:56.789) mod 1000 789Copy the code

Arithmetic Infinities and Nulls

q)42<0W 1b q)-0W<42 1b q)9223372036854775806+1 0W q)-0W-1 0N q)-0W+1 -9223372036854775806 q)0W+1 0N q)0W+2 -0W q)0W+3 - 9223372036854775806.Copy the code

Nulls

The q situation is more interesting. There are no references or pointers, so the notion of an unallocated entity does not arise. Most types have null values that are distinct from “normal” values and occupy the same amount of storage. Some types do not designate a distinct null value because there is no Available bit pattern — i.e., for Boolean, byte and char all underlying bit patterns are meaningfully employed. In this case, the value with no information content serves as a proxy for null.

Binary Nulls

The binary types have no null values. 

Numeric and Temporal Nulls

The numeric and temporal types have their own designated null values. Here the situation is similar to SQL, in that you can distinguish missing data from data whose underlying value is zero. In contrast, there is no universal null value and q nulls take the same space as non-nulls.

An advantage of the q approach is that the null values act like other values in expressions. The tradeoff is that you must use the correct null value in type-checked situations.

Text Nulls

Considering a symbol as variable length text justifies that the symbol null is the empty symbol, designated by a naked back-tick `.

The null value for the char type is the blank character " ".

The value “” is not a null char. It is an empty list of char.

Testing for Null

Always use the unary null to test a value for null, as opposed to =, as it provides a type-independent check. 

q)null 42
0b
q)null `
1b
q)null " "
1b
q)null ""
`boolean$()
Copy the code

Reference: code.kx.com/q4m3/2\_Bas…

By Jeffry A. Borror