Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGCmP-0000hQ-Qb for pgsql-sql@arkaria.postgresql.org; Wed, 19 Feb 2014 19:26:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WGCmO-0002px-M9 for pgsql-sql@arkaria.postgresql.org; Wed, 19 Feb 2014 19:26:00 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGCmN-0002pq-Jw for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 19:25:59 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WGCmL-0007Kf-1J for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 19:25:59 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1WGCmK-0005Le-2a for pgsql-sql@postgresql.org; Wed, 19 Feb 2014 11:25:56 -0800 Date: Wed, 19 Feb 2014 11:25:56 -0800 (PST) From: AlexK To: pgsql-sql@postgresql.org Message-ID: <1392837956043-5792770.post@n5.nabble.com> Subject: 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: 3.5 (+++) 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 Given an array such as ARRAY[1.1,1.2], I need to select both values and indexes, as follows: 1;1.1 2;1.2 The following query does what I want for a simple example: with pivoted_array AS( select unnest(ARRAY[1.1,1.2]) ) select ROW_NUMBER() OVER() AS element_index, unnest as element_value from pivoted_array Is ROW_NUMBER() OVER() guaranteed to always return array's index? If not, how should I predictably/deterministically do it? -- View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-unnest-an-array-with-element-indexes-tp5792770.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