从示例:

>>> from htsql import HTSQL
>>> htsql = HTSQL("pgsql:///htsql_demo")
>>> rows = htsql.produce("/school{name, count(department)}")


如何将行转换为JSON?使用JSON格式化程序会爆炸:

>>> rows = htsql.produce("/school{name, count(department)}/:json")
UnsupportedActionError: unsupported action
While processing:
    /school{name, count(department)}/:json
                                      ^^^^


我正在使用HTSQL 2.3.3

最佳答案

必须通过内部API完成:

from htsql import HTSQL
demo = HTSQL('pgsql:///htsql_demo')
rows = demo.produce('/school{name, count(department)}')

from htsql.core.fmt.emit import emit
with demo:
    text = ''.join(emit('x-htsql/json', rows))

print text


归功于HTSQL用户组的Kirill Simonov。

10-07 12:35