【发布时间】:2013-11-07 00:00:02
【问题描述】:
我想在我的数据库中插入大量 JSON 数据。
[{
"term": "wine",
"name": "Bubba Wine & Spirits",
"address": "1234 N San Fake Rd,"
}, {
"term": "wine",
"name": "Wine Shop",
"address": "123 N Not Real Blvd,"
}]
我使用cl-json 转换为lisp 对象。
(defvar *data*
(decode-json (open "my-json-file.json")))
结果如下:
(((:TERM . "wine") (:NAME . "Bubba Wine & Spirits")
(:ADDRESS . "1234 N San Fake Rd,"))
((:TERM . "wine") (:NAME . "Wine Shop")
(:ADDRESS . "123 N Not Real Blvd,")))
Postmodern 在此处列出了一种使用insert-rows-into 插入多行的方法:https://sites.google.com/site/sabraonthehill/postmodern-examples/postmodern-insert#multiple-row-inserts
(:insert-rows-into 'table :columns 'a 'b :values '((10 20) (30 40)))
这不是默认的 JSON 格式。
看来我有两个选择:
- 按摩数据以适应
- 找到一个按原样处理的函数。
我怀疑:insert-rows-into 做了我想做的事,但我不太确定如何把它塞进去。
【问题讨论】:
标签: sql json postgresql lisp common-lisp