X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9CFC1D1ED3D for ; Wed, 21 Jan 2004 18:20:47 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 03923-01 for ; Wed, 21 Jan 2004 14:20:16 -0400 (AST) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id 4235ED1EC20 for ; Wed, 21 Jan 2004 14:05:27 -0400 (AST) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 781087; Wed, 21 Jan 2004 10:02:32 -0800 Message-ID: <400EBEF0.6060005@joeconway.com> Date: Wed, 21 Jan 2004 10:03:28 -0800 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Rajesh Kumar Mallah , pgsql-sql@postgresql.org Subject: Re: array_lower /array_prepend doubt References: <400E85EC.4000106@trade-india.com> <1648.1074705270@sss.pgh.pa.us> In-Reply-To: <1648.1074705270@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/197 X-Sequence-Number: 16590 Tom Lane wrote: > Rajesh Kumar Mallah writes: >>can anyone explain why >> SELECT array_lower(array_prepend(0, ARRAY[1,2,3]), 1); >>returns 0 not 1 > > Because array_prepend keeps the subscripts of the existing array > elements the same. This was discussed during development of the > code, but I don't see anything in the documentation that mentions it. > It could perhaps be added to the "Functions and Operators" page for arrays, but it is mentioned here: http://www.postgresql.org/docs/current/static/arrays.html#AEN5183 "When a single element is pushed on to the beginning of a one-dimensional array, the result is an array with a lower bound subscript equal to the right-hand operand's lower bound subscript, minus one. When a single element is pushed on to the end of a one-dimensional array, the result is an array retaining the lower bound of the left-hand operand. For example: SELECT array_dims(1 || ARRAY[2,3]); array_dims ------------ [0:2] (1 row) SELECT array_dims(ARRAY[1,2] || 3); array_dims ------------ [1:3] (1 row) " Joe