i'm having one table like
  name | age 
   abc | 20
   pqr | 30
I want result in json array like
{
 [{
   "name":"abc",
   "age":20 
 },
 {
  "name":"pqr",
   "age":30 
 }]
}
I know their is method
row_to_json();
that will be give me only single row of json but i want array, please help me on this
select json_agg(row_to_json(t))
from t
;
                      json_agg                      
----------------------------------------------------
 [{"name":"abc","age":20}, {"name":"pqr","age":30}]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With