Q编程语言

Kdb +附带内置的编程语言,称为 q .它包含标准SQL的超集,可扩展用于时间序列分析,并提供许多优于标准版本的优势.任何熟悉SQL的人都可以在几天内学习 q ,并能够快速编写自己的即席查询.

启动"q"环境

要开始使用kdb +,您需要启动 q 会话.有三种方法可以开始 q 会话 : 去;

  • 只需输入"c:/q/w32/q.exe"在您的运行终端上.

  • 启动MS-DOS命令终端并键入 q .

  • q.exe 文件复制到"C:\ Windows \ System32"并在运行终端上输入" q".

我们假设您正在使用Windows平台.

数据类型

下表提供了支持的数据类型列表 :

名称示例Char类型尺寸
boolean1bb11
byte0xffx41
short23hh52
int23ii64
long23jj78
real2.3ee84
float2.3ff98
char"a"c101
varchar`abs11*
2003.03mm134
date2015.03.17T18:01:40.134z158
分钟08:31u174
second08:31:53v184
time18:03:18.521t194
enum`u $`b,其中u:`a`b*204

原子和列表形成

原子是单个实体,例如,单个数字,字符或符号.在上表(不同数据类型)中,所有支持的数据类型都是原子.列表是一系列原子或其他类型,包括列表.

将任何类型的原子传递给monadic(即单参数函数)类型函数将返回负值,即 -n ,而将这些原子的简单列表传递给type函数将返回正值 n .

示例1  - 原子和列表形成

/ Note that the comments begin with a slash " / " and cause the parser
/ to ignore everything up to the end of the line.

x: `mohan              / `mohan is a symbol, assigned to a variable x
type x                 / let’s check the type of x
-11h                   / -ve sign, because it’s single element.

y: (`abc;`bca;`cab)    / list of three symbols, y is the variable name.

type y
11h                    / +ve sign, as it contain list of atoms (symbol).

y1: (`abc`bca`cab)     / another way of writing y, please note NO semicolon

y2: (`$"symbols may have interior blanks")   / string to symbol conversion
y[0]                   / return `abc
y 0                    / same as y[0], also returns `abc
y 0 2                  / returns `abc`cab, same as does y[0 2]

z: (`abc; 10 20 30; (`a`b); 9.9 8.8 7.7)      / List of different types,
z 2 0                  / returns (`a`b; `abc),
z[2;0]                 / return `a. first element of z[2]

x: "Hello World!"      / list of character, a string
x 4 0                  / returns "oH" i.e. 4th and 0th(first)
element