pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: John D. Burger <john@mitre.org>
Cc: Postgres General <pgsql-general@postgresql.org>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: pgsql-admin@postgresql.org
Subject: Re: [GENERAL] Array assignment behavior (was Re: Stored procedure array limits)
Date: Fri, 29 Sep 2006 13:59:27 -0400
Message-ID: <18110.1159552767@sss.pgh.pa.us> (raw)
In-Reply-To: <CA0C32E2-2371-4297-83AD-2ED9A14E0513@mitre.org>
References: <451C48AB.6090508@pnlassociates.com>
	<9461.1159502232@sss.pgh.pa.us>
	<451D34FD.3050709@pnlassociates.com>
	<451D37C8.8060502@pnlassociates.com>
	<16926.1159546451@sss.pgh.pa.us>
	<595CA7DC-7EC2-47B6-A894-DCD0ED3825F3@pandora.com>
	<CA0C32E2-2371-4297-83AD-2ED9A14E0513@mitre.org>

"John D. Burger" <john@mitre.org> writes:
>>> As of 8.2 we could allow assignment to
>>> arbitrary positions by filling the intermediate positions with nulls.
>>> The code hasn't actually been changed to allow that, but it's  
>>> something we could consider doing now.
>> 
>> At first blush, this strikes me as a bit too magical/implicit. Are  
>> there other languages where sequences behave similarly?

>>> perl -e '@A = (1, 2, 3); print "@A\n"; $A[10] = 10; print "@A\n";'
> 1 2 3
> 1 2 3        10

Actually, now that I look closely, I think the SQL spec demands exactly
this.  Recall that SQL99 only allows one-dimensional, lower-bound-one
arrays.  The specification for UPDATE ... SET C[I] = SV ... reads

              Case:

              i) If the value of C is null, then an exception condition is
                 raised: data exception - null value in array target.

             ii) Otherwise:

                 1) Let N be the maximum cardinality of C.

                 2) Let M be the cardinality of the value of C.

                 3) Let I be the value of the <simple value specification>
                   immediately contained in <update target>.

                 4) Let EDT be the element type of C.

                 5) Case:

                   A) If I is greater than zero and less than or equal to
                      M, then the value of C is replaced by an array A
                      with element type EDT and cardinality M derived as
                      follows:

                      I) For j varying from 1 (one) to I-1 and from I+1 to
                        M, the j-th element in A is the value of the j-th
                        element in C.

                     II) The I-th element of A is set to the specified
                        update value, denoted by SV, by applying the
                        General Rules of Subclause 9.2, "Store assignment",
                        to the I-th element of A and SV as TARGET and
                        VALUE, respectively.

                   B) If I is greater than M and less than or equal to
                      N, then the value of C is replaced by an array A
                      with element type EDT and cardinality I derived as
                      follows:

                      I) For j varying from 1 (one) to M, the j-th element
                        in A is the value of the j-th element in C.

                     II) For j varying from M+1 to I-1, the j-th element in
                        A is the null value.

                    III) The I-th element of A is set to the specified
                        update value, denoted by SV, by applying the
                        General Rules of Subclause 9.2, "Store assignment",
                        to the I-th element of A and SV as TARGET and
                        VALUE, respectively.

                   C) Otherwise, an exception condition is raised: data
                      exception - array element error.

We currently violate case i by allowing the null array value to be
replaced by a single-element array.  I'm disinclined to change that,
as I think our behavior is more useful than the spec's.  But case ii.5.B
pretty clearly describes null-fill, so I think we'd better do that, now
that we can.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <18110.1159552767@sss.pgh.pa.us>
Permalink:  ../18110.1159552767@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18110.1159552767@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, john@mitre.org, pgsql-general@postgresql.org, pgsql-hackers@postgresql.org
  Subject: Re: [GENERAL] Array assignment behavior (was Re: Stored procedure array limits)
  In-Reply-To: <18110.1159552767@sss.pgh.pa.us>
  References: <451C48AB.6090508@pnlassociates.com> <9461.1159502232@sss.pgh.pa.us> <451D34FD.3050709@pnlassociates.com> <451D37C8.8060502@pnlassociates.com> <16926.1159546451@sss.pgh.pa.us> <595CA7DC-7EC2-47B6-A894-DCD0ED3825F3@pandora.com> <CA0C32E2-2371-4297-83AD-2ED9A14E0513@mitre.org> <18110.1159552767@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox