Call row_to_json(row) on any PostgreSQL statement (even statements that don't return a result)

前端 未结 2 1714
逝去的感伤
逝去的感伤 2021-01-26 08:49

I\'m looking for query to always return the JSON representation from PostgreSQL statement, even if there\'s no returning *. Here\'s an example:

WITH         


        
2条回答
  •  终归单人心
    2021-01-26 09:29

    Use returning to get results of insert statement:

    with result as (
        insert into users("name", age) 
        values('drew', 42)
        returning *
    )
    select row_to_json(row) 
    from result as row;
    

提交回复
热议问题