Re: Multidimensional array definition in composite type appears parsed as string - Mailing list pgsql-general

From Tom Lane
Subject Re: Multidimensional array definition in composite type appears parsed as string
Date
Msg-id 16296.1243455519@sss.pgh.pa.us
Whole thread Raw
In response to Multidimensional array definition in composite type appears parsed as string  (miller_2555 <nabble.30.miller_2555@spamgourmet.com>)
Responses Re: Multidimensional array definition in composite type appears parsed as string  (miller_2555 <nabble.30.miller_2555@spamgourmet.com>)
List pgsql-general
miller_2555 <nabble.30.miller_2555@spamgourmet.com> writes:
> I am trying to declare an array of the following compound type:
> CREATE TYPE myschema.mytype AS (
>     sometext            text,
>     onedimarray        text[],
>     multidimarray        text[][]
> );

> The current assignment occurs as follows:
>     myvar    myschema.mytype[] := ARRAY[

> ROW('textaa',ARRAY['textab'],ARRAY[ARRAY['textac1','textac2']])::myschema.mytype,

> ROW('textba',ARRAY['textbb'],ARRAY[ARRAY['textbc1','textbc2']])::myschema.mytype
>                 ];

Looks okay so far ...

> However, each multidimarray in the assignment appears as a string on the
> output from the following statement (declared within a pgSQL function):
> statement: RAISE INFO '%',myvar;
> outputt: INFO:
> {"(textaa,{textab},\"{{textac1,textac2}}\")","(textba,{textbb},\"{{textbc1,textbc2}}\")"}

> I believe that I would have expected the following output from the RAISE
> INFO statement:
> INFO:
> {"(textaa,{textab},{{textac1,textac2}})","(textba,{textbb},{{textbc1,textbc2}})"}

No, you're wrong --- that output is perfectly correct.  The
multidimarray value contains a comma, and therefore it needs to be
double-quoted according to the rules for composite type I/O.  The 1-dim
array value would have gotten quoted, too, had it contained more than
one element.

> I have attempted different explicit typecasts and syntax and have also tried
> adding additional elements to the arrays to see if a one-element array was
> the cause. So far, I have not been able to access the multidimensional array
> in the composite type as an array (though I can perform string functions).

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.

            regards, tom lane

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Bloated Table
Next
From: Tom Lane
Date:
Subject: Re: Bloated Table