【问题标题】:How to insert a row into KDB using qPython如何使用 qPython 在 KDB 中插入一行
【发布时间】:2019-08-26 14:59:41
【问题描述】:

我正在尝试使用脚本连接到 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)

当我尝试使用 insert 时,我收到错误 'type:

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"))')

感谢任何帮助。

【问题讨论】:

    标签: python kdb qpython


    【解决方案1】:

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

    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 函数。

    【讨论】:

    • 可能值得一提的是它只在 vanilla kdb+tick 中定义。因此,如果您不使用 vanilla 脚本,则不一定在所有刻度设置中定义
    • 感谢这对我有用!在将反引号添加到表名后,我收到了一个“长度错误”,必须在我的插入列表中添加一个时间戳。之后我就可以插入了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多