Postgres array of JSON avoid casting -


issuing on postgressql 9.2 following:

create table test (j json, ja json[]); insert test (j) values('{"name":"alex", "age":20}' ); -- works fine insert test (ja) values( array['{"name":"alex", "age":20}', '{"name":"peter", "age":24}'] ); -- returns error 

the first insert works fine. second insert returns error: column "ja" of type json[] expression of type text[]

i can cast type prevent error:

insert test(ja) values( cast (array['{"name":"alex", "age":20}', '{"name":"peter", "age":24}'] json[]) ); -- works fine 

my question if there way avoid casting?

insert test(ja) values ('{"{\"name\":\"alex\", \"age\":20}", "{\"name\":\"peter\", \"age\":24}"}'); 

to avoid confuse escaping cast each string:

insert test(ja) values (array['{"name":"alex", "age":20}'::json, '{"name":"peter", "age":24}'::json]); 

or cast array itself:

insert test (ja) values (array['{"name":"alex", "age":20}', '{"name":"peter", "age":24}']::json[]); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -