Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGDHL-0001uz-Ro for pgsql-sql@arkaria.postgresql.org; Wed, 19 Feb 2014 19:58:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WGDHL-0002DB-BQ for pgsql-sql@arkaria.postgresql.org; Wed, 19 Feb 2014 19:57:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGDHK-0002D4-Cj for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 19:57:58 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGDHC-00078z-8r for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 19:57:57 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WGDHA-0007pG-6T for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 11:57:48 -0800 Date: Wed, 19 Feb 2014 11:57:48 -0800 (PST) From: AlexK To: pgsql-sql@postgresql.org Message-ID: <1392839868185-5792774.post@n5.nabble.com> In-Reply-To: <1392838343105-5792771.post@n5.nabble.com> References: <1392837956043-5792770.post@n5.nabble.com> <1392838343105-5792771.post@n5.nabble.com> Subject: Re: How to unnest an array with element indexes MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org David, The array stores a time series of values for consecutive days. All I need is take an array such as ARRAY[1.1,1.2] and return to the client the following series_start_date + (array_index-1), array_value Based on what you are saying, the following should do it: with pivoted_array AS( select unnest(ARRAY[1.1,1.2]) ), indexed_array AS( select row_number()OVER() AS element_index, unnest as element_value from pivoted_array) SELECT (DATE '2014-02-19' + INTERVAL '1d'*(element_index-1)) AS series_date, element_value AS series_value FROM indexed_array Can you confirm that this behavior is guaranteed and documented. I could not find it in the docs. -- View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-unnest-an-array-with-element-indexes-tp5792770p5792774.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql