Kdb+ Learning Note (2) — Basics

Basics

PeterBanng
1 min readSep 12, 2020
  1. Start and quit environment
>q
KDB+ 4.0 2020.05.04 Copyright © 1993–2020 Kx Systems
q)\\

2. Assign variable

q)w:56                   / numerical variable
q)w
56
q)txt:"Hello World!" / string variable
q)txt
"Hello World!"
q)table1:([]x:1 2 3) / table variable
q)table1
x
-
1
2
3

Define tables

Create table with column names. An empty table without column type is defined with the following syntax:

q)table1:([]name:();gender:();age:();phone:())    /create table
q)table1
name gender age phone
---------------------

Use meta command to display information of the table.

c: column, t: type, f: foreign key, a: attribute

q)meta table1
c | t f a
------| -----
name |
gender|
age |
phone |

Define tables with column type identified.

q) table1:([]name:`$();gender:`boolean$();age:`int$();phone:`$())
q)meta table1
c | t f a
------| -----
name | s
gender| b
age | i
phone | s

Initiate tables with data

q)table1:([]name:`Mary`Jon;gender:`F`M;age:20 22i;phone:1234567 7654321f)
q)table1
name gender age phone
-----------------------
Mary F 20 1234567
Jon M 22 7654321

--

--