The short arrow will return a JSON object while the long arrow will retrieve a specific node from that object.įor instance, in the following snippet, we use the “->” operator with the “->” operator to get only the “pro_name” node from the JSON object: SELECT o_details -> 'pro_description' -> 'pro_name' As product_nameįrom the output, you can observe that the selected node has been accessed from the JSON object.Įxample 5: Querying Filtered Data From the JSON Column Use the short arrow “->” and the long arrow “->” combinedly to query a specific node from a JSON object. The “->” operator retrieves the data in TEXT format.Įxample 4: Querying a Specific Node From a JSON Object in Postgres Replace the “->” operator with the “->” operator to get the data in text format: SELECT o_details -> 'cust_name' As cusatomer_names The output proves that the “->” operator retrieves the data in JSON format.Įxample 3: Querying a JSON Column Using Long Arrow “->” In the following snippet, the “->” operator is used to get the JSON object field by “key”: SELECT o_details -> 'cust_name' As cusatomer_names The output signifies that the SELECT statement successfully retrieves the data from the JSON column.Įxample 2: Querying a JSON Column Using Short Arrow “->” The SELECT statement can be used to query the data from the JSON column: SELECT o_details FROM product_order_details To retrieve data from a sample table named "product_order_details", use the SELECT query: SELECT * FROM product_order_details This section will show you how to query a JSON column in PostgreSQL using the JSON operators.Įxample 1: Querying a JSON Column Using SELECT Statement This write-up presents a detailed guide on how to query JSON data in Postgres via suitable examples. Using these operators, users can get a specific node of a JSON object. The short arrow “->” queries the JSON object by “key”, while the long arrow “->” retrieves the JSON object by “text”. PostgreSQL offers a couple of native JSON operators to query the JSON data, such as the short arrow “->” and the long arrow “->”.
0 Comments
Leave a Reply. |