How to group / select a column of type JSON (PG :: UndefinedFunction: ERROR: could not identify the equality operator for type json)

I want to do

<MODEL>.select("brief_content").group("brief_content")

Here is the table layout

                :id => :integer,
           :content => :json,
     :brief_content => :json

But I got errors,

How can i thank you

companyAlarmLog Load (0.9ms)  SELECT company_alarm_logs.id, company_alarm_logs.name, company_alarm_logs.utc_time, company_alarm_logs.company_alarm_test_id, company_alarm_logs.brief_content, brief_content FROM "company_alarm_logs" GROUP BY brief_content ORDER BY utc_time
E, [2014-06-24T09:40:39.069988 #954] ERROR -- : PG::UndefinedFunction: ERROR:  could not identify an equality operator for type json
LINE 1: ...t, brief_content FROM "company_alarm_logs"  GROUP BY brief_cont...
                                                             ^
: SELECT company_alarm_logs.id, company_alarm_logs.name, company_alarm_logs.utc_time, company_alarm_logs.company_alarm_test_id, company_alarm_logs.brief_content, brief_content FROM "company_alarm_logs"  GROUP BY brief_content  ORDER BY utc_time
Hirb Error: PG::UndefinedFunction: ERROR:  could not identify an equality operator for type json
LINE 1: ...t, brief_content FROM "company_alarm_logs"  GROUP BY brief_cont...
+4
source share
2 answers

Unfortunately, there is no easy way to make direct equality tags jsonin 9.3.

9.3 jsontype does not have an equality operator since it accepts json with duplicate keys (many implementations are expected). It is unclear if {"a":1, "a":2}"equal" {"a":1}or not.

9.4 jsonb, , .

regress=# SELECT '{"a":1, "a":2}'::json = '{"a":1}'::json;
ERROR:  operator does not exist: json = json
LINE 1: SELECT '{"a":1, "a":2}'::json = '{"a":1}'::json;
                                      ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

regress=# SELECT '{"a":1, "a":2}'::jsonb = '{"a":1}'::jsonb;
 ?column? 
----------
 f
(1 row)

, , , , 9.3.

json - , , {"a":1, "b":2} {"b":2, "a":1} .

PL/V8 JavaScript jon JavaScript .

json, b-tree opclass, . SQL - . CREATE OPERATOR CREATE OPERATOR CLASS.

, GROUP BY json 9.3.

9.4 beta1 jsonb.

+9

.group('brief_content:text') . , json. .

+1

Source: https://habr.com/ru/post/1545779/


All Articles