JSON output in Postgresql

后端 未结 4 1176
情深已故
情深已故 2020-12-31 15:18

I hope I am not missing something very obvious here,
I want to get JSON output from a postgres function (I imagine many other had already needed this) and I\'d be happy

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 15:42

    On the server install:
    sudo apt-get install postgresql-plpython-9.4

    Then on your Postgres server:

    CREATE EXTENSION IF NOT EXISTS plpythonu;
    CREATE LANGUAGE plpythonu;
    
    CREATE OR REPLACE FUNCTION prettyprint_json(data text)
     RETURNS json
     AS $$
        import json
        return json.dumps(json.loads(data), indent=4)
     $$ LANGUAGE plpythonu;
    

提交回复
热议问题