Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 运算符不存在:json=json_Sql_Json_Postgresql_Postgresql 9.4_Jsonb - Fatal编程技术网

Sql 运算符不存在:json=json

Sql 运算符不存在:json=json,sql,json,postgresql,postgresql-9.4,jsonb,Sql,Json,Postgresql,Postgresql 9.4,Jsonb,当我尝试从表中选择一些记录时 SELECT * FROM movie_test WHERE tags = ('["dramatic","women", "political"]'::json) sql代码抛出了一个错误 LINE 1: SELECT * FROM movie_test WHERE tags = ('["dramatic","women",... ^ HINT: No operator ma

当我尝试从表中选择一些记录时

    SELECT * FROM movie_test WHERE tags = ('["dramatic","women", "political"]'::json)
sql代码抛出了一个错误

LINE 1: SELECT * FROM movie_test WHERE tags = ('["dramatic","women",...
                                        ^
HINT:  No operator matches the given name and argument type(s). You might      need to add explicit type casts.

********** 错误 **********

ERROR: operator does not exist: json = json
SQL 状态: 42883
指导建议:No operator matches the given name and argument type(s). You might need to add explicit type casts.
字符:37

我是否遗漏了一些信息,或者在哪里可以了解到有关此错误的信息。

您无法比较json值。您可以改为比较文本值:

SELECT * 
FROM movie_test 
WHERE tags::text = '["dramatic","women","political"]'
但是请注意,json类型的值以给定格式存储为文本。因此,比较的结果取决于您是否始终应用相同的格式:

SELECT 
    '["dramatic" ,"women", "political"]'::json::text =  
    '["dramatic","women","political"]'::json::text      -- yields false!
在Postgres 9.4+中,您可以使用类型
jsonb
解决此问题,该类型以分解的二进制格式存储。可以比较此类型的值:

SELECT 
    '["dramatic" ,"women", "political"]'::jsonb =  
    '["dramatic","women","political"]'::jsonb           -- yields true
所以这个查询更可靠:

SELECT * 
FROM movie_test 
WHERE tags::jsonb = '["dramatic","women","political"]'::jsonb

阅读更多信息。

强烈建议使用jsonb而不是文本比较,因为文本比较会报告由于格式等方面的细微差异而产生的不一致结果。非常感谢,这对我非常有帮助!非常感谢。如果它对其他人有帮助,
请列出.where(“营养约束::jsonb->‘素食者’?‘1’”)。首先,谢谢。如果有人知道这样做的背景/原因,我会很高兴:“你不能比较json值。你可以比较文本值。”。这里有什么问题?@poshest-
fullresult->country->0->city->street