Search Postgresql Archives

Re: Multidimensional array definition in composite type appears parsed as string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Tom Lane-2 wrote:
> 
> It sounds like you are using some code that mistakenly thinks that
> double quotes have a semantic meaning here.  They do not.  They are just
> there to delimit members of the row value, not to tell you what type the
> members are.
> 
Note: quoted text abridged per mailing list rules. 

I appreciate the clarification on the output. Given the assignment appears
correct, what is the appropriate method to access the elements of the
multidimensional array? I had mistakenly assumed the following would be
correct:

CREATE TYPE myschema.mytype AS (
sometext text,
onedimarray text[],
multidimarray text[][]
);

CREATE OR REPLACE FUNCTION myschema.mytestfunction() RETURNS void AS $BODY$
DECLARE
myvar myschema.mytype[] := ARRAY[
    
ROW('textaa',ARRAY['textab'],ARRAY[ARRAY['textac1','textac2']])::myschema.mytype,
    
ROW('textba',ARRAY['textbb'],ARRAY[ARRAY['textbc1','textbc2']])::myschema.mytype
];
BEGIN
    	-- Nested loop example to output each element in multidimensional array
for each composite type
    	FOR i IN array_lower(myvar,1)..array_upper(myvar,1) LOOP
    	    	FOR j IN
array_lower((myvar[i]).multidimarray,1)..array_upper((myvar[i]).multidimarray,1)
LOOP
    	    	    	FOR k IN
array_lower((myvar[i]).multidimarray[j],1)..array_upper((myvar[i]).multidimarray[j],1)
LOOP
    	    	    	    	RAISE INFO '%',(myvar[i]).multidimarray[j][k];
    	    	    	END LOOP;
    	    	END LOOP;
    	END LOOP;
END
$BODY$ LANGUAGE 'plpgsql';

When I attempt the above, it appears (myvar[i]).multidimarray[j] is text
instead of an array of text. Currently, (myvar[i]).multidimarray[j][k]
yields NULL in each case and (myvar[i]).multidimarray[j] yields
"{{textac1,textac2}}" and "{{textbc1,textbc2}}". 

Is there an alternate/ preferred method used to access the elements?

Nearly forgot: running Postgres v8.3 on Fedora 10. 

Thanks again.
-- 
View this message in context: http://www.nabble.com/Multidimensional-array-definition-in-composite-type-appears-parsed-as-string-tp23749072p23750913.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux