Thread: arrays broken in 7.1.3? also, support for embedded tables present?

arrays broken in 7.1.3? also, support for embedded tables present?

From
"Robby Dermody"
Date:
Hi, I'm running 7.1.3 on a redhat linux system, using the rpm packages from
the postgresql site:

[nova@naomi scripts]$ rpm -qa|grep postgresql
postgresql-libs-7.1.3-0.onms.5
postgresql-server-7.1.3-0.onms.5
postgresql-python-7.1.3-0.onms.5
postgresql-7.1.3-0.onms.5
postgresql-contrib-7.1.3-0.onms.5
postgresql-docs-7.1.3-0.onms.5

I've been having some problems with getting arrays to work (either I'm doing
something stupid, or they seem to be broken).

Here's what I try:

allshotup=# CREATE TABLE foo (bla0 text, bla1 varchar(20)[], bla2
char(20)[], bla3 text[]);
CREATE

allshotup=# INSERT INTO foo (bla0) VALUES ('test');
INSERT 19408 1

allshotup=# UPDATE foo SET bla1[1] = 'bla1', bla2[1] = 'bla2', bla3[1] =
'bla3' WHERE bla0='test';
UPDATE 1

allshotup=# SELECT * FROM foo;
 bla0 | bla1 | bla2 | bla3
------+------+------+------
 test |      |      |
(1 row)

allshotup=# SELECT bla1[1] FROM foo WHERE bla0='test';
 bla1
------

(1 row)

-----------------------------
etc....

Am I doing something wrong? (Note that I don't think this matters, but I
have installed the array-related contrib stuff that defines the operators
like *=, etc)

Lastly, I was wondering if anyone knew if support for embedding tables
exists? I've heard that at one point pgsql had this, but the object
relational stuff kind of got out of date and this got deprecated.

Thanks.

Robby Dermody

Re: arrays broken in 7.1.3? also, support for embedded tables present?

From
Tom Lane
Date:
"Robby Dermody" <robbyd@robbyd.org> writes:
> allshotup=# CREATE TABLE foo (bla0 text, bla1 varchar(20)[], bla2
> char(20)[], bla3 text[]);
> CREATE

> allshotup=# INSERT INTO foo (bla0) VALUES ('test');
> INSERT 19408 1

> allshotup=# UPDATE foo SET bla1[1] = 'bla1', bla2[1] = 'bla2', bla3[1] =
> 'bla3' WHERE bla0='test';
> UPDATE 1

> allshotup=# SELECT * FROM foo;
>  bla0 | bla1 | bla2 | bla3
> ------+------+------+------
>  test |      |      |
> (1 row)

Right at the moment I don't believe there's any support for assigning
into one element of an array that's NULL; the array just stays NULL.
This could doubtless be improved, but no one's really stepped up to
work on the array code in a long time.  It's got lotsa shortcomings
besides this one :-(

If you feel motivated to work on this, start by looking at
ExecEvalArrayRef() in execQual.c.  You'd need to hack both it and
the arrayfuncs.c routines it calls in order to be smarter about
initially-NULL array values.

            regards, tom lane