Creating a table in KDB using Q

Creating a table in KDB using Q

Creating and populating a simple keyed table with time series identifiers (sym), dates (date) and values (val)

[sourcecode language="kdb"]

q)TestTable : ([sym:`symbol$(); date:`date$()] val:`float$())


The contents of the table will be displayed simply by typing the table name at the command prompt:

q> TestTable

And an empty table will be displayed, just the meta-data ie the column names with no rows shown:

sym date| val ——–| —

We can now insert our first value:

q> insert [`TestTable] (`GBPUSD; 2011.02.10; 1.5074)

On typing the table name, the contents are displayed in tabular format

q> TestTable

you will now see

sym    date      | val —————–| ——

EURUSD 2011.02.10| 1.5074

You can also

q> select * from TestTable

and this generates the same result:

sym    date      | val -----------------| ------

GBPUSD 2011.02.10| 1.5074

Is it possible to insert several rows at once?

Yes,  Note that there is no space in “`USDJPY`ARSRUB”.

q> insert [`TestTable] ([sym: `USDJPY`ARSRUB; date: 2009.02.10 2009.02.11]; val: 1.2874 10.252969)

The result of the previous insert statement is:

Leave a Reply