I have a file named data.json. The structure is like this:
{ "PrimKey1": { "layout": "normal", "col1": "PrimKey1",
"__colll2__": "sometext", "col3": 9, "OTHERCOLUMN":"dontneedthis", "col4": ["texxt"] },
... ,
{"PrimKey500": { "layout": "normal", "col1": "PrimKey500",
"col2": "someothertext", "col3": 1, "col4": ["texxtagain"] }}
The data is loaded into table a_json with:
CREATE TABLE a_json (
data json
);
\copy a_json FROM 'mypath/data.json/';
Since the table is not in the expected format, I create a new table named b.
CREATE TABLE b (
col1 text PRIMARY KEY,
col2 text,
col3 numeric,
col4 text
);
where the columns are named after the columns that I need from data.json.
Now, I want to insert everything from table a_json into b. I tried
INSERT INTO b
SELECT * from a_json json_each(data);
and got
ERROR: index row requires 1945656 bytes, maximum size is 8191