KDB:为什么升级时会出现类型错误?

KDB:为什么升级时会出现类型错误?,kdb,Kdb,我将列指定为字符串类型。为什么会出现以下错误: q)test: ([key1:"s"$()] col1:"s"$();col2:"s"$();col3:"s"$()) q)`test upsert(`key1`col1`col2`col3)!(string "999"; string "693"; string "943"; string "249") 'type [0] `test upsert(`key1`col1`col2`col3)!(string "999"; string "6

我将列指定为字符串类型。为什么会出现以下错误:

q)test: ([key1:"s"$()] col1:"s"$();col2:"s"$();col3:"s"$())
q)`test upsert(`key1`col1`col2`col3)!(string "999"; string "693"; string "943"; 
string "249")

'type
[0]  `test upsert(`key1`col1`col2`col3)!(string "999"; string "693"; string "9
43"; string "249")
您有几个问题:

  • 引号中的字符数组是一个字符串,因此无需编写
    字符串“abc”
  • 字符串“aaa”将把字符串拆分为多个字符串
  • 您最初定义的类型是符号
    “s”
    ,而不是字符串
这将允许您作为符号插入:

q)test: ([key1:"s"$()] col1:"s"$();col2:"s"$();col3:"s"$())
q)`test upsert(`key1`col1`col2`col3)!`$("999"; "693"; "943"; "249")
`test
这将使它们保持为字符串:

q)test: ([key1:()] col1:();col2:();col3:())
q)`test upsert(`key1`col1`col2`col3)!("999"; "693"; "943"; "249")
`test
看一看这两个元素在metas中的差异

嗯,,
Sean

要做到这一点,您可以删除在测试中定义的列表类型:

q)test: ([key1:()] col1:();col2:();col3:())
q)test upsert (`key1`col1`col2`col3)!("999";"693";"943";"249")
key1 | col1  col2  col3
-----| -----------------
"999"| "693" "943" "249"
出现类型错误的原因是“s”对应的是符号列表,而不是字符列表。您可以使用.Q.ty:

q).Q.ty `symbol$()
"s"
q).Q.ty `char$()
"c"
(通常)将键设置为嵌套的字符列表不是一个好主意,您可能会发现最好将它们设置为整数(
“i”
)或长(
“j”
),如下所示:

将键设为整数/长将使upsert函数表现良好。还要注意的是,表是字典列表,因此每个字典都可以单独追加,也可以追加一个表:

q)`test upsert (`key1`col1`col2`col3)!(9;4;6;2)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 4    6    2
q)`test upsert (`key1`col1`col2`col3)!(8;6;2;3)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 4    6    2
8   | 6    2    3
q)`test upsert (`key1`col1`col2`col3)!(9;1;7;4)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 1    7    4
8   | 6    2    3
q)`test upsert ([key1: 8 7] col1:2 4; col2:9 3; col3:1 9)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 1    7    4
8   | 2    9    1
7   | 4    3    9
q)`test upsert (`key1`col1`col2`col3)!(9;4;6;2)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 4    6    2
q)`test upsert (`key1`col1`col2`col3)!(8;6;2;3)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 4    6    2
8   | 6    2    3
q)`test upsert (`key1`col1`col2`col3)!(9;1;7;4)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 1    7    4
8   | 6    2    3
q)`test upsert ([key1: 8 7] col1:2 4; col2:9 3; col3:1 9)
`test
q)test
key1| col1 col2 col3
----| --------------
9   | 1    7    4
8   | 2    9    1
7   | 4    3    9