Friday 31 July 2020

How To Convert Table Records Into JSON Array In PostgreSQL | row_to_json...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.





-- Purpose is to convert table records into JSON (JavaScript Object Notation)





--row_to_json()



select * from actor;



select row_to_json(row(actor_id,first_name)) from actor;





select row_to_json(actor_alias)

from (select actor_id,first_name from actor) actor_alias;





select row_to_json(actor) from actor;





explain

select array_to_json(array_agg(row_to_json(actor_alias)))

from (select * from actor) actor_alias;




1 comment:

  1. Hi...!!!! I'm From Colombia....
    I need to know how I can convert the data to JSON in a new column of a table through a postgres query

    ReplyDelete