Re: Array performance - Mailing list pgsql-performance

From Jim C. Nasby
Subject Re: Array performance
Date
Msg-id 20060324125245.GB90527@pervasive.com
Whole thread Raw
In response to Array performance  (Ruben Rubio Rey <ruben@rentalia.com>)
Responses Re: Array performance
List pgsql-performance
On Fri, Mar 24, 2006 at 01:41:50PM +0100, Ruben Rubio Rey wrote:
> Hi,
>
> I have a select like
>
> SELECT (array[20]+array[21]+ ... +array[50]+array[51]) as total
> FROM table
> WHERE
> (array[20]+array[21]+ ... +array[50]+array[51])<5000

http://www.varlena.com/GeneralBits/109.php might provide some useful
insights. I also recall seeing something about sum operators for arrays,
but I can't recall where.

> AND array[20]<>0
> AND array[21]<>0
> ...
> AND array[50]<>0
> AND array[51])<>0

Uhm... please don't tell me that you're using 0 in place of NULL...

You might be able to greatly simplify that by use of ANY; you'd need to
ditch elements 1-19 though:

... WHERE NOT ANY(array) = 0

See http://www.postgresql.org/docs/8.1/interactive/arrays.html
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

pgsql-performance by date:

Previous
From: Svenne Krap
Date:
Subject: Performance problems with multiple layers of functions
Next
From: "Jim C. Nasby"
Date:
Subject: Re: Performance problems with multiple layers of functions