将Json数组作为单独的列插入Postgres

时间:2016-08-03 13:30:34

标签: sql json postgresql

我使用以下方法在PostgreSQL中创建了一个表:

CREATE TABLE TEST (MULTIPROCESS VARCHAR(20), HTTP_REFERER VARCHAR(50));

我尝试将JSON数组插入表中。如下所示

INSERT INTO TEST
SELECT MULTIPROCESS, HTTP_REFERER
FROM json_populate_record(
    NULL::TEST_POS,
    '[{"multiprocess":true,"http_referer": "http://localhost:9000/"}, {"multiprocess": false,"http_referer": "http://localhost:9002/"}]'
);

它抛出错误:

[Error Code: 0, SQL State: 22023]  ERROR: cannot call json_populate_record on an array

如何将JSON数组数据插入表中,如下所示

MULTIPROCESS           HTTP_REFERER
  true             http://localhost:9000/
  false            http://localhost:9002/

0 个答案:

没有答案