5

I would like to use dot notation to extract the year of a date.

q) myDate:2014.01.01;
q) myDate.year
2014i           / works OK

But when inside a function,

f:{[x] :x.year};
f[myDate]

I get an error (I use Studio for KDB+)

An error occurred during execution of the query.
The server sent the response:
x.year

What's going wrong?

4

1 回答 1

5

根据code.kx 上的这个页面,这种行为是 q 的一个怪癖。为了解决这个问题,您可以使用 cast 功能。

q)f:{[x] :`year$x}
q)f[myDate]
2014i
于 2014-04-16T18:51:54.390 回答