Search code examples
databasetime-serieskdb

Is it possible to craete a table with only one emtpy primary key column in Kdb+?


I tried to create an empty table with only one column, and this column is set as primary key. But I failed, until there is another column within table.

Is it supposed not to create an emtpy table with only one keyed column ?

// this failed
et :([pk:`symbol$()])
// this makes, means simgle emtpy key column is available
emptyTable:([primaryKey:`symbol$()] c1:())
// this makes too, means single empty column is available
t1:([]c1:())

Solution

  • A keyed table is not a table, it is a dictionary mapping a table of key records to a table of value records. It has type 99h. You can see how the keyed table is formed using parse

    q)parse "([pk:`symbol$()]c1:())"
    !
    (+:;(!;,,`pk;(enlist;($;,`symbol;()))))
    (+:;(!;,,`c1;(enlist;())))
    

    Using "!" to create a dictionary requires two arguments otherwise a parse error is returned