- KDB+ Tutorial
- KDB+ - Home
- KDB+ Architecture
- KDB+ - Overview
- KDB+ - Architecture
- Q Programming Language
- Q Programming Language
- Q Language - Type Casting
- Q Language - Temporal Data
- Q Language - Lists
- Q Language - Indexing
- Q Language - Dictionaries
- Q Language - Table
- Q Language - Verb & Adverbs
- Q Language - Joins
- Q Language - Functions
- Q Language - Built-in Functions
- Q Language - Queries
- Q - Inter-Process Communication
- Q - Message Handler (.Z Library)
- Q Advanced Topics
- Q Language - Attributes
- Q Language - Functional Queries
- Q Language - Table Arithmetic
- Q Language - Tables on Disk
- Q Language - Maintenance Functions
- KDB+ Useful Resources
- KDB+ - Quick Guide
- KDB+ - Useful Resources
- KDB+ - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Q Programming Language
Kdb+ comes with its built-in programming language that is known as q. It incorporates a superset of standard SQL which is extended for time-series analysis and offers many advantages over the standard version. Anyone familiar with SQL can learn q in a matter of days and be able to quickly write her own ad-hoc queries.
Starting the “q” Environment
To start using kdb+, you need to start the q session. There are three ways to start a q session −
Simply type “c:/q/w32/q.exe” on your run terminal.
Start the MS-DOS command terminal and type q.
Copy the q.exe file onto “C:\Windows\System32” and on the run terminal, just type “q”.
Here we are assuming that you are working on a Windows platform.
The following table provides a list of supported data types −
|enum||`u$`b, where u:`a`b||*||20||4|
Atom and List Formation
Atoms are single entities, e.g., a single number, a character or a symbol. In the above table (of different data types), all supported data types are atoms. A list is a sequence of atoms or other types including lists.
Passing an atom of any type to the monadic (i.e. single argument function) type function will return a negative value, i.e., –n, whereas passing a simple list of those atoms to the type function will return a positive value n.
Example 1 – Atom and List Formation
/ 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 / return `abc y 0 / same as y, 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 x: “Hello World!” / list of character, a string x 4 0 / returns “oH” i.e. 4th and 0th(first) element