create table test_json ( a json, id serial); insert into test_json (a) values ( '{"a":"foo", "b":"bar"}' ); select * from test_json where a->>'b' = 'bar'; select * from test_json where a->a='foo'; alter table test_json add json_data json ; -- CREATE TEMP TABLE x (aa text,bb timestamp );select json_agg(( phonenumber,created_at )::x ) from (select phonenumber,created_at from inventory.phonenumber where json_data->>'Phonenumber'>'0426085000' limit 3 ) a -[ RECORD 1 ]------------------------------------------------ json_agg | [{"aa":"04611920056","bb":"2015-03-03 08:20:12"}, | {"aa":"0462770051","bb":"2015-03-03 08:20:12"}, | {"aa":"0462770303","bb":"2015-03-03 08:20:12"}]