Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 249FB9FB499 for ; Sat, 24 Feb 2007 19:04:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 49491-09 for ; Sat, 24 Feb 2007 19:04:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from talk.nabble.com (www.nabble.com [72.21.53.35]) by postgresql.org (Postfix) with ESMTP id A95699FB41E for ; Sat, 24 Feb 2007 19:04:52 -0400 (AST) Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1HL5wh-00087P-9Q for pgsql-sql@postgresql.org; Sat, 24 Feb 2007 15:04:51 -0800 Message-ID: <9138745.post@talk.nabble.com> Date: Sat, 24 Feb 2007 15:04:51 -0800 (PST) From: chrisj To: pgsql-sql@postgresql.org Subject: Re: can someone explain confusing array indexing nomenclature In-Reply-To: <200702200942.18500.achill@matrix.gatewaynet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: chrisj.wood@sympatico.ca References: <8971770.post@talk.nabble.com> <200702151224.12455.achill@matrix.gatewaynet.com> <8989242.post@talk.nabble.com> <200702161034.43399.achill@matrix.gatewaynet.com> <9009934.post@talk.nabble.com> <200702200942.18500.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.033 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200702/247 X-Sequence-Number: 27581 I guess you could say the [2] is discarded since the value "2" is at the to= p or beyond the top of the range. Achilleas Mantzios wrote: >=20 > =CE=A3=CF=84=CE=B9=CF=82 =CE=A0=CE=B1=CF=81=CE=B1=CF=83=CE=BA=CE=B5=CF=85= =CE=AE 16 =CE=A6=CE=B5=CE=B2=CF=81=CE=BF=CF=85=CE=AC=CF=81=CE=B9=CE=BF=CF= =82 2007 20:35, =CE=BF/=CE=B7 chrisj =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: >> I am quite sure the [2] is not discarded, easy enough to test but I don'= t >> have access to PG at the moment. >=20 > Well it should, since >=20 > dynacom=3D# SELECT=20 > (CAST( '{{meeting,lunch},{training,presentation}}' as text[][]))[1:1]; > text > ------------------- > {{meeting,lunch}} > (1 row) >=20 > dynacom=3D# SELECT=20 > (CAST( '{{meeting,lunch},{training,presentation}}' as text[][]))[1:1][1]; > text > ------------- > {{meeting}} > (1 row) >=20 > dynacom=3D# SELECT=20 > (CAST( '{{meeting,lunch},{training,presentation}}' as text[][]))[1:1][2]; > text > ------------------- > {{meeting,lunch}} > (1 row) >=20 > dynacom=3D# SELECT=20 > (CAST( '{{meeting,lunch},{training,presentation}}' as text[][]))[1:1][3]; > text > ------------------- > {{meeting,lunch}} > (1 row) >=20 > dynacom=3D# SELECT=20 > (CAST( '{{meeting,lunch},{training,presentation}}' as > text[][]))[1:1][1000]; > text > ------------------- > {{meeting,lunch}} > (1 row) >=20 > dynacom=3D# =20 >=20 >> >> Achilleas Mantzios wrote: >> > =CE=A3=CF=84=CE=B9=CF=82 =CE=A0=CE=AD=CE=BC=CF=80=CF=84=CE=B7 15 =CE= =A6=CE=B5=CE=B2=CF=81=CE=BF=CF=85=CE=AC=CF=81=CE=B9=CE=BF=CF=82 2007 18:55,= =CE=BF/=CE=B7 chrisj =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: >> >> Thanks Achilleas, >> >> >> >> I see what you are saying, but if we consider just the index "[2]" fo= r >> a >> >> moment, >> >> it means something different depending upon the context (in one case >> it >> >> means "2" and in the other case it means "1:2") and the context is >> >> determined by the format of indexes on other dimensions. >> >> >> >> I believe I understand....but incredibly confusing. >> > >> > Now that i think about it again, i speculate that the [2] is discarded= . >> > >> >> - chris >> >> >> >> Achilleas Mantzios wrote: >> >> > =CE=9E=C2=A3=CE=9F=C2=84=CE=9E=CE=89=CE=9F=C2=82 =CE=9E=EF=BF=BD=CE= =9E=CE=85=CE=9F=C2=84=CE=9E=C2=AC=CE=9F=C2=81=CE=9F=C2=84=CE=9E=C2=B7 14 = =CE=9E=C2=A6=CE=9E=CE=85=CE=9E=C2=B2=CE=9F=C2=81=CE=9E=CE=8F=CE=9F=C2=85=CE= =9E=C2=AC=CE=9F=C2=81=CE=9E=CE=89=CE=9E=CE=8F=CE=9F=C2=82 2007 21:31, =CE= =9E=CE=8F/=CE=9E=C2=B7 >> >> >> >> chrisj >> > >> > =CE=9E=C2=AD=CE=9E=C2=B3=CE=9F=C2=81=CE=9E=C2=B1=CE=9F=C2=88=CE=9E=CE= =85: >> >> >> given the following table: >> >> >> >> >> >> protocal2=3D> select * from sal_emp ; >> >> >> name | pay_by_quarter | schedule >> >> >> >> >> -------+---------------------------+------------------------------------ >> >> >> >> >>--- ---- Bill | {10000,10000,10000,10000} | >> >> >> {{meeting,lunch},{training,presentation}} >> >> >> Carol | {20000,25000,25000,25000} | >> >> >> {{breakfast,consulting},{meeting,lunch}} >> >> >> (2 rows) >> >> >> >> >> >> why do the following two queries yield different results?? >> >> >> >> >> >> protocal2=3D> SELECT schedule[1][2] FROM sal_emp WHERE name =3D 'B= ill'; >> >> >> schedule >> >> >> ---------- >> >> >> lunch >> >> >> (1 row) >> >> >> >> >> >> protocal2=3D> SELECT schedule[1:1][2] FROM sal_emp WHERE name =3D >> 'Bill'; >> >> >> schedule >> >> >> ------------------- >> >> >> {{meeting,lunch}} >> >> >> (1 row) >> >> > >> >> > The [n:m] notation denotes a slice of the array (not element). >> >> > So schedule[1][2] is the Array element on 2nd col of 1st row, >> >> > while schedule[1:1][2] could mean >> >> > the second row of the subarray schedule[1:1][1:2]. >> >> > So these two are foundamentally different things. >> >> > In my 7.4 even if you gave >> >> > SELECT schedule[1:1][888] FROM sal_emp WHERE name =3D 'Bill'; >> >> > you would still get {{meeting,lunch}} as a result. >> >> > (Right or wrong is another story). >> >> > Anyway the first time you query for a "text", >> >> > the second time you query for a "text[]", so you should expect >> >> > different results. >> >> > -- >> >> > Achilleas Mantzios >> >> > >> >> > ---------------------------(end of >> >> >> >> broadcast)--------------------------- >> >> >> >> > TIP 3: Have you checked our extensive FAQ? >> >> > >> >> > http://www.postgresql.org/docs/faq >> > >> > -- >> > Achilleas Mantzios >> > >> > ---------------------------(end of >> broadcast)--------------------------- >> > TIP 3: Have you checked our extensive FAQ? >> > >> > http://www.postgresql.org/docs/faq >=20 > --=20 > Achilleas Mantzios >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at >=20 > http://www.postgresql.org/about/donate >=20 >=20 --=20 View this message in context: http://www.nabble.com/can-someone-explain-con= fusing-array-indexing-nomenclature-tf3229165.html#a9138745 Sent from the PostgreSQL - sql mailing list archive at Nabble.com.