--Let us take the sales table for using WHERE CLAUSE
postgres=# select * from sales;
id | sales_info
----+----------------------------------------------------------------------------------
1 | { "customer": "NIJAM", "PRODUCTS": {"product_name": "choclate","total_item": 6}}
2 | { "customer": "ABU", "PRODUCTS": {"product_name": "badam","total_item": 5}}
3 | { "customer": "UMAR", "PRODUCTS": {"product_name": "mobile","total_item": 1}}
(3 rows)
--To find out what are the products bought customer UMAR I use the following query
postgres=# SELECT sales_info ->>'customer' as customer_name,sales_info ->>'PRODUCTS' ->>'product_name'
as name_of_product from sales where sales_info ->>'customer'='UMAR';
ERROR: operator does not exist: text ->> unknown
LINE 1: ...stomer' as customer_name,sales_info ->>'PRODUCTS' ->>'produc...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
SOLUTION:
- HERE i specified first json object(->) format finnaly i called json object format (->) this is not a problem.
- other wise if you specify firstly as json text format (->>) finally if you give json object format (->) or json text format (->>) what ever it is json will not know fist values surely it will throw error.