Bardiya Choupani
Bardiya Choupani

Reputation: 165

KDB/KX appending table to a file without reading the entire file

I'm new to KDB ( sorry if this question is dumb). I'm creating the following table

q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)`dsPricing insert(123;2003.03.23;1.0;3.0;4.0;2.0;1000)
q)`dsPricing insert(123;2003.03.24;1.0;3.0;4.0;2.0;2000)
q)save `:dsPricing

Let's say after saving I exit. After starting q, I like to add another pricing item in there without loading the entire file because the file could be large

q)`dsPricing insert(123;2003.03.25;1.0;3.0;4.0;2.0;1500)

I've been looking at .Q.dpft but I can't really figure it out. Also this table/file doesn't need to be partitioned.

Thanks

Upvotes: 3

Views: 2859

Answers (1)

user3576050
user3576050

Reputation: 171

You can upsert with the file handle of a table to append on disk, your example would look like this:

`:dsPricing upsert(123;2003.03.25;1.0;3.0;4.0;2.0;1500)

You can load the table into your q session using get, load or \l

 q)get `:dsPricing
id  date      | open close high low volume
--------------| --------------------------
123 2003.03.23| 1    3     4    2   1000  
123 2003.03.24| 1    3     4    2   2000  
123 2003.03.25| 1    3     4    2   1500  

.Q.dpft will save a table splayed(one file for each column in the table and a .d file containing column names) with a parted attribute(p#) on one of the symbol columns. Any symbol columns will also be enumerated by .Q.en.

Upvotes: 5

Related Questions