Closed mgburns closed 1 year ago
Thank you @mgburns for your feedback and for reaching out!
This use case is not supported... but makes sense supporting it (e.g. by adding a dump_json
helper function).
Right now, you can do the following workaround:
$ spyql 'IMPORT json AS js SELECT js.dumps(.a, default=lambda x: None if x is null else str(x)) AS a FROM {"a": {"foo": 1, "bar": null}} TO sql(table="mytable")'
INSERT INTO "mytable"("a") VALUES ('{"foo": 1, "bar": null}');
Please let me know if it solves your issue. Thanks!
Gah, great solution -- that did the trick! Thanks for the quick workaround.
Use Case
I'm using the CLI to import JSON Line log files into a Postgres database. One of the columns I'm trying to import is
jsonb
, and needs to be inserted as a JSON string.Approach
This works fine until it hits a null value:
I also tried passing the
default
kwarg tojson.dumps
and hit a different error:Very open to alternative approaches; thank you so much for making this great tool available. :)