Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ew9Mn-0002MT-MQ for pgsql-general@arkaria.postgresql.org; Wed, 14 Mar 2018 16:35:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ew9Mm-0004Hn-GX for pgsql-general@arkaria.postgresql.org; Wed, 14 Mar 2018 16:35:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ew9Ml-0004Hd-U9 for pgsql-general@lists.postgresql.org; Wed, 14 Mar 2018 16:35:04 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ew9Mh-0002qe-8m for pgsql-general@lists.postgresql.org; Wed, 14 Mar 2018 16:35:02 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 65D8421C2464 for ; Wed, 14 Mar 2018 19:34:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.104] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 36D6D21C244C for ; Wed, 14 Mar 2018 19:34:56 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1521045296; bh=/nU5kza+bEiF0RF1Wrxj5RwqmTnty7Y3mnNmA+Fj9Mg=; h=Subject:To:References:From:Date:In-Reply-To; b=kYNkpqKEeIx8M+1bxBZlQSCSmpvPRFIj4IvkkgIIBg6NDyaz60ixvYuRSEcyEswZ0 7YSmrIpYhRNfAyTfDjkiaf4SZZlyGQkTkliox7HcJ+5/PelTBSLDQWOHslB7wqqqDp Ky5p2s1rvfaB47XVZcOZHWLw7L3swbEBcA5IR46Q= Subject: Re: Extract elements from JSON array and return them as concatenated string To: pgsql-general@lists.postgresql.org References: From: "Ivan E. Panchenko" Message-ID: Date: Wed, 14 Mar 2018 19:34:55 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Alex, SELECT  string_agg(x->>'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; Regards, Ivan Panchenko Postgres Professional the Russian PostgreSQL Company 14.03.2018 19:27, Alexander Farber пишет: > Good afternoon, > > A PostgreSQL 10.3 table contains JSON data like: > > [{"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"}] > > Please suggest, how to extract only the "letter" values and > concatenate them to a string like "ABCD"? > > I suppose at the end I should use the ARRAY_TO_STRING function, but > which JSON function to use for extracting the "letter" values to an array? > > I keep looking at > https://www.postgresql.org/docs/10/static/functions-json.html but > haven't found a good one yet > > Thank you > Alex >