X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4DF33D1B8C5 for ; Thu, 28 Aug 2003 21:28:57 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 06980-06 for ; Thu, 28 Aug 2003 18:28:48 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id C889CD1B8C6 for ; Thu, 28 Aug 2003 18:28:45 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 52454; Thu, 28 Aug 2003 13:45:04 -0700 Message-ID: <3F4E73C4.3080407@joeconway.com> Date: Thu, 28 Aug 2003 14:27:32 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Chris Faulkner Cc: pgsql-sql@postgresql.org Subject: Re: length of array References: In-Reply-To: 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: 200308/347 X-Sequence-Number: 14963 Chris Faulkner wrote: > I would like to do it like this in Oracle > > select field from table N where [conditions] > and NVL(N.level[1],0) = 0 > and NVL(N.level[2],0) = 0 > and NVL(N.level[3],0) = 0 > and NVL(N.level[4],0) = 0 > > So if a row only has two elements in the array, but the first two both had > values "0", then the row would return. At the moment, I have this : > > and N.level[1] = 0 > and N.level[2] = 0 > and N.level[3] = 0 > and N.level[4] = 0 > > but my row with 2 elements in the array won't be returned with this > condition. Is this what you're looking for? regression=# select * from t1; id | f1 ----+----------- 1 | {1,2} 2 | {0,0,0} 3 | {0,0,0,0} 3 | {1,2,3,0} (4 rows) regression=# SELECT * FROM t1 WHERE COALESCE(f1[1],0) = 0 and COALESCE(f1[2],0) = 0 and COALESCE(f1[3],0) = 0 and COALESCE(f1[4],0) = 0; id | f1 ----+----------- 2 | {0,0,0} 3 | {0,0,0,0} (2 rows) Joe