2022.08.19 01:51 PM
I want to create a KDB table with an array:
- for a regular one, I would have t:([]time:`time$();price:`float$()); for each time, there is only price
- I want to have a table with a price array for each time. should I create it using t:([]time:`time$();price:()) or t:([]time:`time$();price:(()))
2022.08.19 02:48 PM - edited 2022.08.19 02:49 PM
Both works, as (())
is interpreted the same as ()
. For this reason the first form is preferred. Note that the data type of price
is determined by the data type of cell in the first row.
q)t:([] time:`time$(); price:())
q)meta t
c | t f a
-----| -----
time | t
price|
q)`t upsert (.z.t; 10 11f)
`t
q)t
time price
------------------
21:42:07.028 10 11
q)meta t
c | t f a
-----| -----
time | t
price| F
q)`t upsert (.z.t; 10 11)
`t
q)t
time price
------------------
21:42:07.028 10 11
21:44:30.724 10 11
q)meta t
c | t f a
-----| -----
time | t
price| F
2022.08.19 02:53 PM
To define any column in a table as a list or an array, you can simply specify the column type with an empty set of parentheses, (), on definition. Following this definition, you can then upsert the price array along with the time value, and the column value for that table will be assigned to a float list type (upper-case F in meta command indicates the column is a list of floats, as opposed to a float atom which would be identified with a lower case f):
q)t:([]time:`time$();price:())
q)`t upsert (.z.t;60.57 60.61)
`t
q)t
time price
------------------------
21:47:06.298 60.57 60.61
q)meta t
c | t f a
-----| -----
time | t
price| F
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.