首页 > 解决方案 > 如何使用 qPython 在 KDB 中插入一行

问题描述

我正在尝试使用脚本连接到 KDB 并使用 qpython (https://github.com/exxeleron/qPython)将行插入到 KDB 中的表中。我的表具有以下列类型:
"symbol","symbol","int","timestamp","string","string","symbol","symbol","string","string","string"

我尝试使用'.u.upd',但这不返回任何内容并且不更新表:

time = [numpy.timedelta64((numpy.datetime64(datetime.now()) - today), 'ms') for x in range(1)]
row = [qlist(['test'], qtype=QSYMBOL_LIST), qlist(['test'], qtype=QSYMBOL_LIST), qlist([1], qtype=QINT_LIST), qlist(time, qtype=QTIME_LIST),
        qlist([['t','e','s','t']], qtype=QSTRING_LIST), qlist([['t','e','s','t']], qtype=QSTRING_LIST), qlist(['test'], qtype=QSYMBOL_LIST), qlist(['test'], qtype=QSYMBOL_LIST),
        qlist([['t','e','s','t']], qtype=QSTRING_LIST), qlist([['t','e','s','t']], qtype=QSTRING_LIST), qlist([['t','e','s','t']], qtype=QSTRING_LIST)]

result = self.q.sendSync('.u.upd', numpy.string_('tableName'), row)

当我尝试使用插入时,我收到错误“类型:

result = self.q('tableName insert (`test;`test;1i;2019.08.09D12:00:00.123123123;("t"; "e"; "s"; "t");("t"; "e"; "s"; "t");`test;`test;("t"; "e"; "s"; "t");("t"; "e"; "s"; "t");("t"; "e"; "s"; "t"))')

任何帮助表示赞赏。

标签: pythonkdbqpython

解决方案


使用插入时,您应该通过引用而不是值传递表名,.ie

result = self.q('`tableName insert (`test;`test;1i;2019.08.09D12:00:00.123123123;("t"; "e"; "s"; "t");("t"; "e"; "s"; "t");`test;`test;("t"; "e"; "s"; "t");("t"; "e"; "s"; "t");("t"; "e"; "s"; "t"))')

注意表名前面的反引号。

对于您的其他问题,.u.upd具体仅存在于实时/自动报价系统设置中,而不是内置的 q 函数。


推荐阅读