PostgreSQL Nested JSON Querying -


At PostgreSQL 9.3.4, I have a JSON type column called "person" and the data stored in it is in the {Dogs: [{Breed: & lt; & Gt;, Name: & lt; & Gt;}, {Breed: & lt; & Gt;, Name: & lt; & Gt;}]} I want to retrieve the dog breed at Index 0. Here are two questions:

does not work

  db = & gt; Person- & gt; 'Dogs' - & gt; & Gt; 0-> Choose 'breed' from people where ID = 77; Error: Operator does not exist: Text - & gt; Unknown line 1: person- & gt; Select 'Dogs' - & gt; & Gt; 0-> 'Bree ... ^ Hint: An operator does not match given given name and logic type (fairs). You may need to explicitly enter   

Works < / Strong>

  Select (person-> dogs' ->> 0) :: json- & gt; 'Breed' from es_config_app_solutiondraft where id = 77; ? Column? ----------- "Westli" (1 line)   

Why type casting is necessary? Is not it disabled? Am I doing something wrong or is it necessary for postgrazon support?

The reason for this is that the operator - & gt; & Gt; JSON receives array elements as text, you need an artist to change its result back to JSON.

You are the operator -> By selecting :

 , you can eliminate this unnecessary artist-> person> & gt; 'Dogs' - & gt; 0-> 'Breed' to people where id = 77;    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -