【问题标题】:Impossible to export SQLite query results to JSON?无法将 SQLite 查询结果导出为 JSON?
【发布时间】:2021-08-18 01:46:04
【问题描述】:

我找到了这个answer 并尝试了这个:

sqlite3 peds.db '.mode json' '.once out.json' 'select startn, rel, endn, desc, priority, finding, explanation from dx_graph FOR JSON AUTO'

但它说:

Execution finished with errors.
Result: near "sqlite3": syntax error
At line 1:
sqlite3

在我看来,这已经不可能了?我找不到任何更新的答案。

顺便说一句,我在我的 SQLite DB 浏览器的“执行 SQL”选项卡中使用此代码。

【问题讨论】:

  • 这个命令应该在命令提示符下执行。
  • 谢谢,还是不行
  • 您可以在 SQLite DB 浏览器中从 File->Export->Table(s) 导出到 json 到 json
  • 谢谢,但这并不能回答我的问题,因为我希望导出特定的查询。
  • 使用您的查询创建视图:CREATE VIEW myview AS SELECT ....。也可以导出。

标签: json sqlite


【解决方案1】:

这最终为我工作(插入终端)

sqlite3 -json '/Users/anon/DxHero Godot/Data/peds.db' 'select startn, rel, endn, desc, priority, finding, explanation from dx_graph' >  '/Users/gtye/DxHero Godot/Data/dx_graph.json'

更普遍的答案:

sqlite3 -json '<db file path>' '<sqlite query>' > '<output file path>'

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多