John,

> > What happens if someone manually shifted an element onto the front
> > of a Pg 1-D array, and the string was changed to '[-1:4]{.........}'
> > does your parser handle that?
> 
> No, I've never even seen that syntax.  Will the database itself actually
> return something like that?  If so, can you give me an example that
> demonstrates it?
>
> What sort of querying can be done on ARRAY types?
> > cf. Pg's ANY() and ALL() functions.
> I'm not too familiar with the similar functions in Pg.  Can you post some
> example SQL that uses the Pg array operators in a WHERE clause?

wasabi=> create table atest (x integer[]);

wasabi=> insert into atest (x) values ('{4,5,6}');

wasabi=> select * from atest;
    x
---------
 {4,5,6}
(1 row)

# ok - this is the 'simplified' array string representation
# when the array is 1-based.

wasabi=> update atest set x = array_prepend(3, x);

wasabi=> select * from atest;
        x
-----------------
 [0:3]={3,4,5,6}

# hmm - we prepended any element to the array so it is
# now 0-based, from 0 to 3. this is how Pg tells us.
# you can also use the array_dims() function

wasabi=> insert into atest (x) values (ARRAY[4,4,4,4,4]);

# alternate, nicer ARRAY syntax 

wasabi=> select * from atest where 4 = ANY(x);
        x
-----------------
 [0:3]={3,4,5,6}
 {4,4,4,4,4}
(2 rows)

# selected rows where 1 or more array elements had value 4

wasabi=> select * from atest where 4 = ALL(x);
      x
-------------
 {4,4,4,4,4}
(1 row)

# selected rows where every element in the array had value 4

NOTE: you must write 4=ANY(x) -- ANY(x)=4 fails syntax

Lots more information here:

http://www.postgresql.org/docs/8.1/interactive/arrays.html
http://www.postgresql.org/docs/8.1/interactive/functions-array.html

where 4 = ANY(x);
-- 
Torsten Seemann <[EMAIL PROTECTED]>
Victorian Bioinformatics Consortium



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to