PostgreSQL transform json to composite type -


i'm experimenting new json functions in postgresql 9.4 , find of them usefull. example transforming composite type json in order end processes map functions result easier.

but can't working other way, transforming json string object of composite type.

please note functioncall to_json(...) used here simulate json string has exact structure of composite type

drop type if exists mytype_1; drop type if exists mytype_0;  create type mytype_0 (     id smallint,     name text );  create type mytype_1 (     since timestamp,     objects mytype_0[] );   select json_populate_record(null::mytype_1,                              to_json( row( now(),                                            array[row(1,'name1')::mytype_0,                                                  row(2,'name2')::mytype_0,                                                  row(4,'name3')::mytype_0])::mytype_1)) 

the code returns

error:  malformed array literal: "[{"id":1,"name":"name1"},{"id":2,"name":"name2"},{"id":4,"name":"name3"}]" detail:  "[" must introduce explicitly-specified array dimensions.  


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -