Reputation: 5744
I'm looking for a way to build up a DuckDB table akin to read_json_auto with the following constraints:
Is there a way to do so?
Example: Say you have a JSON array such as
[
{"a": 1, "b": 2},
{"a": 10, "b": 20}
]
read_json_auto would now automatically infer the columns, and create a table with 2 rows, and 2 columns (column "a" and "b").
Given my constraints above, I thought maybe I can build up a table manually, and then somehow expand its format;
CREATE TABLE Source(items JSON);
INSERT INTO Source VALUES ('{"a": 1, "b": 2}');
INSERT INTO Source VALUES ('{"a": 10, "b": 20}');
// now what?
I haven't found any way to do the next step though - which is, having some convenient way of expanding this table into a table with 2 columns "a" and "b", similar to what read_json_auto would do.
Upvotes: 3
Views: 977
Reputation: 86
One option would be to use the CLI and read/write stdin/stdout like in this example: https://duckdb.org/docs/api/cli#reading-from-stdin-and-writing-to-stdout
Upvotes: 0