[英]how separate json field in postgres and got the field
I'm working with mongoDB, and I used a wrapper mongo/Postegres. 我正在使用mongoDB,并且使用了包装器mongo / Postegres。 Now, I can find my tables and data.
现在,我可以找到我的表和数据了。
I want to do some statistics but I can't reach objects that got json type in Postgres. 我想做一些统计,但我无法到达Postgres中具有json类型的对象。
My problem is that I got all the object in json but I need to separate the fields. 我的问题是我将所有对象都保存在json中,但是我需要分隔字段。
I used this : 我用这个:
CREATE FOREIGN TABLE rents( _id NAME, status text, "from" json )
SERVER mongo_server
OPTIONS (database 'tr', collection 'rents');
The field "from" is an object. 字段“来自”是一个对象。
I found something like this : 我发现了这样的事情:
enter code here
but nothing happened 但是什么都没发生
The error (why a screenshot??) means that the data are not in valid json
format. 错误(为什么要显示屏幕截图??)表示数据不是有效的
json
格式。
As a first step, you could define the column as type text
instead of json
. 第一步,您可以将列定义为
text
类型,而不是json
。 Then querying the foreign table will probably work, and you can see what is actually returned and why PostgreSQL thinks that this is not valid JSON. 然后查询外部表可能会起作用,您可以看到实际返回的内容以及PostgreSQL为什么认为这是无效的JSON。
Maybe you can create a view on top of the foreign table that converts the value to valid JSON for further processing. 也许您可以在外部表的顶部创建一个视图,将该视图转换为有效的JSON以进行进一步处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.