您无法比较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+中,您可以使用type来解决此问题
jsonb,该类型以分解后的二进制格式存储。可以比较以下类型的值:
SELECT '["dramatic" ,"women", "political"]'::jsonb = '["dramatic","women","political"]'::jsonb-- yields true
因此此查询更加可靠:
SELECT * FROM movie_test WHERe tags::jsonb = '["dramatic","women","political"]'::jsonb
阅读有关JSON类型的更多信息。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)