【问题标题】:qPython bytes type exception in sync query同步查询中的 qPython 字节类型异常
【发布时间】:2017-07-31 09:15:46
【问题描述】:

我正在尝试使用以下选择语句查询 KDB:{select from order where OrderID = x}。传入参数时,它会不断抛出 b'lenghth 异常。我已经使用 .encode() 方法(latin-1 和 utf-8)尝试了 numpy.string_numpy.bytes_ 和常规 bytes

当我查询一条记录来调查 OrderID 列的类型时,它告诉我列类型是bytes

我做错了什么?不确定docs 中的破折号应该是什么意思。谢谢!

【问题讨论】:

    标签: python kdb qpython


    【解决方案1】:

    听起来kdb端OrderID的类型是一个字符列表。在这种情况下,您需要使用like 在查询中进行比较:

    {select from order where OrderID like x}
    

    然后你应该能够使用常规的 Python 字符串作为参数,.e.g.

    q.sync("{select from order where OrderID like x}", "my_order_id")
    

    只要您不在参数x 中使用任何通配符,那么它只会匹配确切的字符串。即

     q)"one" like "one"
    1b
    q)"ones" like "one"
    0b
    q)"ones" like "one*"
    1b
    

    【讨论】:

    • 救世主!!像魅力一样工作!非常感谢(整天都在为此苦苦挣扎)。
    猜你喜欢
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    相关资源
    最近更新 更多