I have a Type with below structure.
create type t_attr as (id character varying(50), data character varying(100));
I get text/varchar value through a user-defined function. The value looks like below.
txt := 'id1#data1' , 'id2#data2';
(In the above example, there are 2 values separated by comma, but the count will vary).
I'm trying to store each set into the t_attr array using the below code. Since each set will contain a # as separator I use it to split the id and data values. For testing purpose I have used only one set below.
DO
$$
DECLARE
attr_array t_attr[];
txt text := 'id1#data1';
BEGIN
attr_array[1] := regexp_split_to_array(txt, '#');
END;
$$
LANGUAGE plpgsql;
But the above code throws error saying 'malformed record literal' and 'missing left paranthesis'.
Can someone please help on how to store this data into array? Thanks.