Subject: Strange array_in behaviour

From: Aaron Roydhouse <[email-masked]>
Date: Thu, 23 Jun 1994 14:26:53 +1200

The array_in proceeds frequently rejects seemingly valid
multidimensional array string constants, consider the attached
example. Can anyone explain this behaviour? It would be quite painful
if I have to make all sub-arrays of equal size in string constants.

On a related note, what are the storage requirements of
multidimensional arrays? Just the number of elements appended, or the
product of the maximum size in each dimension?

Perhaps I would be better advised to use a bunch of single dimensional
arrays?

Aaron.
----------------------------------------------------------------------
* create foo (list = oid[][])\g

Query sent to backend is "create foo (list = oid[][])"
CREATE
Go 
* append foo (list = "{{1,2,3,4,5},{1,2,3,4,5}}")\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1,2,3,4,5}}")"
APPEND 50418
Go 
* append foo (list = "{{1,2,3,4,5},{1,2,3,4}}")\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1,2,3,4}}")"
APPEND 50419
Go 
* append foo (list = "{{1,2,3,4,5},{1,2,3}}")\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1,2,3}}")"
APPEND 50420
Go 
* append foo (list = "{{1,2,3,4,5},{1,2}}")\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1,2}}")"
WARN:Jun 23 02:17:43:array_in: illformed array constant

Go 
* append foo (list = "{{1,2,3,4,5},{1}}"\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1}}""
WARN:Jun 23 02:17:51:array_in: illformed array constant

Go 
* append foo (list = "{{1,2,3,4,5},{}}"\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{}}""
WARN:Jun 23 02:18:06:array_in: illformed array constant

Go 
* append foo (list = "{{1,2,3,4,5}}")\g

Query sent to backend is "append foo (list = "{{1,2,3,4,5}}")"
APPEND 50421
Go 
* 

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "[email-masked]"

   If this fails, send mail to "[email-masked]" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================

---

From: Sunita Sarawagi <[email-masked]>
Date: Thu, 30 Jun 1994 17:00:59 -0700

> if I have to make all sub-arrays of equal size in string constants.

You have to provide one of two things to the array_in procedure
to enable it to work correctly. Either you provide the full *complete
string* (I will describe a *complete string* next) or  provide the
exact dimension of the array after the attribute name. In the Postgres
array implementation we do *not* keep any indexing information about
the array global to the whole relation. So, it is not necessary to
have all array tuples of the relation to be of the same size and
dimension. But, each individual tuple has to follow the rule I just
mentioned for the code to behave sanely.

A *complete string* in the context of a multi-dimensional array is one
that lists all elements of the array so that it is possible to get
all information about the dimensionality of the array from the string.
In your example "{{1,2,3,4,5},{1,2,3,4,5}}" is a complete string and
"{{1,2,3,4,5},{1,2,3}}" is not (Although array_in wrongly accepts the
string it does not store the full string as you can see by doing a retrieve).  
Incomplete strings like "{{1,2,3,4,5},{1,2}}" can be readily accepted
by specifying the dimension as:

* append foo (list[2][5] = "{{1,2,3,4,5},{1,2}}")\g

The unspecified elements are initialized to 0.

A session is given below:

Query sent to backend is "append foo (list = "{{1,2,3,4,5},{1,2,3,4,5}}")"
APPEND 377370
Go 
* append foo (list[3][2] = "{11,12}")\g

Query sent to backend is "append foo (list[3][2] = "{11,12}")"
APPEND 377371
Go 
* retrieve (foo.all)
\g

Query sent to backend is "retrieve (foo.all) "
---------------
| list        |
---------------
| {{1,2,3,4,5},{1,2,3,4,5}}|
---------------
| {{11,12},{0,0},{0,0}}|
---------------

-----------------------------------------------------------

> product of the maximum size in each dimension?

This should be clear from the above explanation.

------------------------------------------------------------------

Sunita Sarawagi