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

时间:2018-11-22 16:25:28

标签: kdb

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

<p>ěščřžýáíé<p><img alt="" src="http://www.test.com/img001.jpg" style="width: 100px; height: 100px;"></p></p>

2 个答案:

答案 0 :(得分:1)

您遇到了一些问题:

  • 带引号的字符数组 是一个字符串,因此无需编写string "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

看看两者之间的差异

HTH, 肖恩

答案 1 :(得分:1)

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

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"或long("j")可能更好,如下所示: :

test: ([key1:"j"$()] col1:"j"$();col2:"j"$();col3:"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
相关问题