title: Extract elements from JSON array and return them as concatenated string
body: <p>A PostgreSQL 10 table contains JSON data like (here an <a href="http://sqlfiddle.com/#!17/9eecb/11342" rel="nofollow noreferrer">SQL Fiddle</a>):</p>
  
  <pre><code>[
      {
          "col": 7,
          "row": 12,
          "value": 3,
          "letter": "A"
      },
      {
          "col": 8,
          "row": 12,
          "value": 10,
          "letter": "B"
      },
      {
          "col": 9,
          "row": 12,
          "value": 1,
          "letter": "C"
      },
      {
          "col": 10,
          "row": 12,
          "value": 2,
          "letter": "D"
      }
  ]
  </code></pre>
  
  <p>How to extract only the "letter" values and concatenate them to a string like</p>
  
  <pre><code>ABCD
  </code></pre>
  
  <p>I suppose at the end I should use the <a href="https://www.postgresql.org/docs/10/static/functions-array.html" rel="nofollow noreferrer">ARRAY_TO_STRING</a> function, but which <a href="https://www.postgresql.org/docs/10/static/functions-json.html" rel="nofollow noreferrer">JSON function</a> to use for extracting the "letter" values to an array?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Got a tip at the very helpful PostgreSQL mailing list too:</p>
  
  <pre><code>SELECT string_agg(x-&gt;&gt;'letter','') FROM json_array_elements(
  
  '[{"col": 7, "row": 12, "value": 3, "letter": "A"}, {"col": 8, "row": 12, "value": 10, "letter": "B"}, {"col": 9, "row": 12, "value": 1, "letter": "C"}, {"col": 10, "row": 12, "value": 2, "letter": "D"}]'::json
  
  ) x;
  </code></pre>