Re: Arrays - a good idea? - Mailing list pgsql-sql

From Achilleus Mantzios
Subject Re: Arrays - a good idea?
Date
Msg-id Pine.LNX.4.44.0311190953560.28604-100000@matrix.gatewaynet.com
Whole thread Raw
In response to Re: Arrays - a good idea?  (Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>)
List pgsql-sql
O kyrios Yasir Malik egrapse stis Nov 18, 2003 :

> Hello,
> I don't think there's any reason you should use arrays.  You can do
> everything using tables, and it probably would be easier to use tables
> instead.  Extracting information from arrays is also more
> difficult if you're using something like JDBC or the connectivity
> available in PHP.  I don't know the criteria of when arrays are necessary,
> but I cannot think of an example where arrays are absolutely necessary
> Regards,
> Yasir

PgSQL herself uses arrays in some occasions:

pg_class.relacl and
pg_constraint.conkey, pg_constraint.confkey are such cases.

I think arrays *should* be used when the array fits the model.
For instrance if we want to provide Tree hierarchy capability in a table
one way is to do it with the genealogical approache where
the parents of a node are represented as an array of ids.
(This plus the intarray package makes the performance great).

Also if we want to store polynomial furmulae, we can do that
by storing the coefficients in an float array.
We then can write a C function that calculates the value
of this polyonym given the formula (the array) and X.

In these situations we could use the relational model
but the performance would be prohibiting.

On the other hand, ofcourse, when the size of the child
'relation' is not bounded, we should use the pure relational approach.

As a conclusion, use arrays when

- The size is bounded (Not necessarilly limited)
- The array fits in the model (Intuitively)
- Performance is an issue

In other words:
- Dont be afraid of arrays
- Dont overdo it with arrays!

P.S.

PgSQL jdbc driver does a good job in reading arrays.
Unfortunately when storing arrays, the String must be programmatically
formatted.

> 
> On Tue, 18 Nov 2003, Paul Ganainm wrote:
> 
> > Date: Tue, 18 Nov 2003 22:05:00 -0000
> > From: Paul Ganainm <paulsnewsgroups@hotmail.com>
> > To: pgsql-sql@postgresql.org
> > Subject: [SQL] Arrays - a good idea?
> >
> >
> >
> > Hi all,
> >
> >
> > Even though PostgreSQL supports arrays, is it a good idea to use them? I
> > mean, they
> >
> > a) don't conform to the relational model
> >
> > and
> >
> > b) are not transportable
> >
> >
> > so if one is designing an app, should one use them?
> >
> > When should they not/never be used? What are the criteria for justifying
> > their use?
> >
> >
> > Paul...
> >
> >
> > --
> >
> > plinehan__AT__yahoo__DOT__com
> >
> > C++ Builder 5 SP1, Interbase 6.0.1.6 IBX 5.04 W2K Pro
> >
> > Please do not top-post.
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> >       subscribe-nomail command to majordomo@postgresql.org so that your
> >       message can get through to the mailing list cleanly
> >
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
> 

-- 
-Achilleus



pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: Array fields in Postgresql...
Next
From: Michael Glaesemann
Date:
Subject: Re: Need Help : Query problem