title: Postgres JSON Query within list
body: <p>I have the following data in a matches table:</p>
  
  <pre><code>{"Id":1,"Teams":[{"Name":"TeamA","Players":[{"Name":"AAA"},{"Name":"BBB"}]},{"Name":"TeamB","Players":[{"Name":"CCC"},{"Name":"DDD"}]}],"TeamRank":[1,2]}
  
  {"Id":2,"Teams":[{"Name":"TeamA","Players":[{"Name":"CCC"},{"Name":"BBB"}]},{"Name":"TeamB","Players":[{"Name":"AAA"},{"Name":"DDD"}]}],"TeamRank":[1,2]}
  </code></pre>
  
  <p>Ultimately I want to get a list of unique team names.</p>
  
  <p>Following <a href="https://stackoverflow.com/questions/18833970/querying-inside-postgres-json-arrays">This Question</a> I have been trying to access the Team Name property using the following:</p>
  
  <pre><code>SELECT json_array_elements(match-&gt;&gt;'Teams') FROM matches
  </code></pre>
  
  <p>This returns</p>
  
  <pre><code>ERROR: function json_array_elements(text) does not exist
  SQL state: 42883
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Character: 1560
  </code></pre>
  
  <p>I have also tried json_array_elements(match->>'Teams'::json) and json_array_elements(to_json(match->>'Teams')) to no avail.</p>
  
  <p>But the following query</p>
  
  <pre><code>SELECT match-&gt;&gt;'Teams' FROM matches;
  </code></pre>
  
  <p>Returns</p>
  
  <pre><code>"[{"Name":"TeamA","Players":[{"Name":"AAA"},{"Name":"BBB"}]},{"Name":"TeamB","Players":[{"Name":"CCC"},{"Name":"DDD"}]}]"
  "[{"Name":"TeamA","Players":[{"Name":"CCC"},{"Name":"BBB"}]},{"Name":"TeamB","Players":[{"Name":"AAA"},{"Name":"DDD"}]}]"
  </code></pre>