ROW_TO_JSON
postgres中的函數將表的一行轉換爲JSON對象。postgreSQL如何將表中的多行轉換爲JSON數組
select row_to_json(result) from (select * from employee) as result;
select row_to_json(result) from (select * from student) as result;
給了我三排:
{"salary":null,"age":65,"address":null,"id":111,"name":"NAME"}
{"salary":null,"age":21,"address":null,"id":222,"name":"SURNAME"}
{"dob":"1997-03-02","name":"Mediocore","passed":true,"id":555}
的前兩排是從employee
表,而最後一排是從student
表。
如果我想將整個結果集從一個表中放入一個JSON對象數組中? 例如。
[{"salary":null,"age":65,"address":null,"id":111,"name":"NAME"}, {"salary":null,"age":21,"address":null,"id":222,"name":"SURNAME"}]
作爲單行而不是兩行分開。
有沒有相當於TABLE_TO_JSON
的東西?
您運行的是什麼版本.. –
的PostgreSQL 9.6與pgAdmin的4 V4 – izengod
啊,然後@a_horse_with_no_name給出最好的答案:) –