Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id AD5426336AE for ; Wed, 8 Apr 2009 12:35:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 07700-01 for ; Wed, 8 Apr 2009 12:35:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og101.obsmtp.com (exprod7og101.obsmtp.com [64.18.2.155]) by mail.postgresql.org (Postfix) with SMTP id 4A4CC6335FF for ; Wed, 8 Apr 2009 12:35:01 -0300 (ADT) Received: from source ([209.85.218.159]) by exprod7ob101.postini.com ([64.18.6.12]) with SMTP ID DSNKSdzEJGjblbkQEuyHrEmY+nsAiHAPeHCr@postini.com; Wed, 08 Apr 2009 08:35:02 PDT Received: by bwz3 with SMTP id 3so225736bwz.38 for ; Wed, 08 Apr 2009 08:35:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.107.199 with SMTP id c7mr464553fap.31.1239204900185; Wed, 08 Apr 2009 08:35:00 -0700 (PDT) In-Reply-To: <24AD6A221A5B4B03B87163A772D2F8BB@squarepi.com> References: <89DBB5874E89413698A8E275E5E79154@squarepi.com> <4ECCF5BAADF94C5E9FD5CF2FA52CD061@squarepi.com> <49DCBB2F.7040406@esilo.com> <49DCBDBB.9070303@esilo.com> <24AD6A221A5B4B03B87163A772D2F8BB@squarepi.com> Date: Wed, 8 Apr 2009 16:35:00 +0100 Message-ID: <4136ffa0904080835h76463e3bqfc4b87659e78ceed@mail.gmail.com> Subject: Re: Array types From: Greg Stark To: John Lister Cc: Andrew Chernow , pgsql-hackers@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200904/446 X-Sequence-Number: 136549 On Wed, Apr 8, 2009 at 4:11 PM, John Lister wrote: > Cheers for the pointers. Am i right in thinking that if i get an array of > arrays, the nested arrays are sent in wire format as well - it seems to be > from the docs. No, you can't easily get an array of arrays in Postgres. You can get multi-dimensional arrays but that's one big array with multiple dimensions. The text output form does look like an array of arrays but they don't behave like you might think they would: postgres=# select array[array[1,2,3,4],array[5,6,7,8]]; array ----------------------- {{1,2,3,4},{5,6,7,8}} (1 row) postgres=# select '{{1,2,3,4},{5,6,7,8}}'::int[]; int4 ----------------------- {{1,2,3,4},{5,6,7,8}} (1 row) postgres=# select ('{{1,2,3,4},{5,6,7,8}}'::int[])[1]; int4 ------ (1 row) postgres=# select ('{{1,2,3,4},{5,6,7,8}}'::int[])[1][1]; int4 ------ 1 (1 row) > > Secondly, comments are a bit scarse in the code, but am i also right in > thinking that an array indexing can start at an arbitrary value? This seems > to be what the lbound value is for... or is this a addition to deal with > nulls eg, {null, null, null, 4} would have a lbound of 3.... (or both) No, nulls are handled using a bitmap inside the array data structure. Array bounds don't have to start at 1, they can start below 1 or above 1. postgres=# select ('[-2:-1][5:8]={{1,2,3,4},{5,6,7,8}}'::int[])[-2][5]; int4 ------ 1 (1 row) -- greg