Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import JSON #62

Open
ihinsdale opened this issue Mar 12, 2019 · 0 comments
Open

Unable to import JSON #62

ihinsdale opened this issue Mar 12, 2019 · 0 comments

Comments

@ihinsdale
Copy link

ihinsdale commented Mar 12, 2019

I'm on OSX 10.14, go version 1.11.5, installed pgfutter from source. I'm unable to import JSON into Postgres (tried with Postgres versions 9.4 and 10.6). When I try importing a test file with 4 objects in JSON Lines format, pgfutter says 1 row was imported successfully and 3 failed:

pgfutter --ignore-errors --jsonb json test
 0 B / 53 B [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------]   0.00%
{"foo":"bar"}
{"banana":3}
{"apple":[4]}
 53 B / 53 B [====================================================================================================================================================================================================================] 100.00% 0s

Looking in the db table, no rows were created.

I've fallen back to importing via COPY reading from stdin:

# HACK: COPY, when running in text mode, unescapes backslashes, which renders JSON that contains that escape character invalid. So we need to prevent
# COPY from doing that. To do so, we use csv mode plus QUOTE and DELIMITER characters that are prohibited by JSON spec.
# Cf. https://stackoverflow.com/a/52355439, http://adpgtech.blogspot.com/2014/09/importing-json-data.html
< $file psql -h localhost -p 5432 mydb -c "COPY ingest (data) FROM STDIN csv quote e'\x01' delimiter e'\x02';"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant