Oops... sent to Jeroen only... sorry.
Actually, it's interesting... postgres handles multidimensional arrays
strangely. For one thing, an array can't be an anyelement, and the operator
ARRAY(SELECT ...) won't work to create array of arrays.
In fact, I think a multidim array is not an array of arrays (as in, say,
Java). So box is a special case, not a multidim array.
-- create table:
[local]:[EMAIL PROTECTED] create table test_arr(a int[][]);
CREATE TABLE
-- strange table created:
[local]:[EMAIL PROTECTED] \d test_arr;
Table "public.test_arr"
Column | Type | Modifiers
--------+-----------+-----------
a | integer[] |
[local]:[EMAIL PROTECTED] insert into test_arr values( '{{1,2},{3},{5,6}}');
INSERT 1614992210 1
[local]:[EMAIL PROTECTED] select * from test_arr;
a
---------------------
{{1,2},{3,0},{5,6}}
(1 row)
-- multidim indexing works:
[local]:[EMAIL PROTECTED] select a[1][2] from test_arr;
a
---
2
(1 row)
-- array of array doesn't:
[local]:[EMAIL PROTECTED] select (a[1])[2] from test_arr;
ERROR: cannot subscript type integer because it is not an array
-- this error, and \d, made me guess you can access the array as 1d.
[local]:[EMAIL PROTECTED] select a[1] from test_arr;
a
--------
(null)
(1 row)
-- so it's not even an array of arrays.
--
G.
On 2005.11.03. 18:57, [EMAIL PROTECTED] wrote:
Merkel Marcel wrote:
That's a creative approach... Why doesn't it work? I haven't worked
with
arrays in postgres yet, so I don't know much about them.
It simply gives me NULL as result don't know why. In the postgre manual
I found that snippet (chapter 9.9) :
(On a sidenote, this causes no end of confusion in the world: the short
name for PostgreSQL is Postgres, not Postgre!)
I tried some combinations and the following works:
SELECT (box[0])[0], (box[0])[1], (box[1])[0], (box[1])[1] FROM ...
Looks like C-style A[i][j] indexing doesn't work for multidimensional
arrays. Maybe they normally use Fortran-style A[j,i] or Pascal-style
A[i,j] indexing...
Jeroen
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general