I have a Type with below structure.
create type t_attr as (id character varying(50), data character varying(100));
I get text value through a user-defined function. In the above type both id and data will have comma-separated values. The length of the array can vary between 1 and 100. Below is a sample text value I get as function input parameter which if converted to array should have length 2.
txt text := '("id1,id2,id3", "dat1,data2,dat3"), ("id4,id5,id6", "dat4,dat5,dat6")';
In txt, 'id1,'id2,id3' is the id of type t_attr[1] and so on.
I tried as below to convert it to array, but I'm always getting either 'malformed record literal' and 'Too many columns'.
arr_attr := array[txt]::t_attr[];
arr_attr should look like this after loading with sample data:
arr_attr[1]should look like("id1,id2,id3", "data1,data2,data3")arr_attr[2]will be("id4,id5,id6","data4,data5,data6")
txt text :=contains 9 single quotes, so I don't know what exactly you mean with that line. I don't know any programming language where such a line would be valid.