B05999
B05999

Reputation: 53

Type error of getting average by id in KDB

I am trying make a function for the aggregate consumption by mid in a kdb+ table (aggregate value by mid). Also this table is being imported from a csv file like this: table: ("JJP";enlist",")0:`:data.csv

Where the meta data is for the table columns is: mid is type long(j), value(j) is type long and ts is type timestamp (p).

data of the table

Here is my function: agg: {select avg value by mid from table} but I get the 'type [0] get select avg value by mid from table

error message

But the type of value is type long (j). So I am not sure why I can't get the avg I also tried this with type int.

Upvotes: 0

Views: 162

Answers (3)

THarveyWork
THarveyWork

Reputation: 36

Value can't be used as a column name because it is keyword used in kdb+. Renaming the column should correct the issue.

Upvotes: 2

terrylynch
terrylynch

Reputation: 13572

You can rename the value column as you read it:

flip`mid`val`ts!("JJP";",")0:`:data.csv

Upvotes: 1

rianoc
rianoc

Reputation: 3651

value is a keyword and should not be used as a column name.

https://code.kx.com/q/ref/value/

You can remove it as a column name using .Q.id

https://code.kx.com/q/ref/dotq/#qid-sanitize

q)t:flip`value`price!(1 2;1 2)
q)t
value price
-----------
1     1
2     2
q)t:.Q.id t
q)t
value1 price
------------
1      1
2      2

Or xcol

https://code.kx.com/q/ref/cols/#xcol

q)(enlist[`value]!enlist[`val]) xcol t
val price
---------
1   1
2   2

Upvotes: 2

Related Questions