简体   繁体   English

如何在 PostgreSQL 中导入 JSON 文件:COPY 1

[英]How to import JSON file in PostgreSQL: COPY 1

I'm new at PostgreSQL.我是 PostgreSQL 的新手。 I'm trying to import JSON file into PostgreSQL table.我正在尝试将 JSON 文件导入 PostgreSQL 表。 I created an empty table:我创建了一个空表:

covid19=# CREATE TABLE temp_cov(
covid19(# data jsonb
covid19(# );

and tried to copy my data from JSON in this table with this command in Command line:并尝试使用命令行中的以下命令从此表中的 JSON 复制我的数据:

cat output.json | psql -h localhost -p 5432 covid19 -U postgres -c "COPY temp_cov (data) FROM STDIN;" 

The output was just "COPY 1" and when I open my table in psql with output 只是“COPY 1”,当我在 psql 中打开我的表时

SELECT * FROM temp_cov;

But this command goes without an end and with this output.但是这个命令没有尽头,还有这个 output。

输出

Unfortunately, I couldn't find an answer or some similar problem solution.不幸的是,我找不到答案或一些类似的问题解决方案。 Thank you in advance for your advices.预先感谢您的建议。

Also my json file is already modified to "not pretty" form and it has over than 11k lines.此外,我的 json 文件已经修改为“不漂亮”的形式,并且它有超过 11k 行。

Your data is there.你的数据在那里。 psql is sending the row to the pager (likely more ?), and the pager can't deal with it very usably because it is too big. psql 正在将行发送到寻呼机(可能more ?),并且寻呼机无法很好地处理它,因为它太大了。 You can turn off the pager ( \pset pager off inside psql) or set the pager to a better program (PAGER=less or PSQL_PAGER=less as environment variables), but really none of those is going to be all that useful for viewing giant JSON data.您可以关闭寻呼机(在 psql 中\pset pager off )或将寻呼机设置为更好的程序(PAGER=less 或 PSQL_PAGER=less 作为环境变量),但实际上这些对于查看巨型程序都没有太大用处JSON 数据。

You have your data in PostgreSQL, now what do you want to do with it?您在 PostgreSQL 中有您的数据,现在您想用它做什么? Just looking at it within psql's pager is unlikely to be interesting.仅仅在 psql 的寻呼机中查看它不太可能有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM