I
I
Ivan2020-09-07 15:57:00
JSON
Ivan, 2020-09-07 15:57:00

Carriage return \r\n\ JSON?

I make a request like this

WITH T AS
        (SELECT userid, dbid, queryid, query, calls, round(total_time) as total_time, rows as total_rows, round(total_time/calls) as average_time 
                FROM pg_stat_statements 
                ORDER BY average_time 
                DESC LIMIT 5)
SELECT json_object_agg(userid, row_to_json(T))                                                                                                                                           
FROM T

As a result, I get the following information
[{"userid":"16384","dbid":"1848551","queryid":1057054500,"query":"SELECT DISTINCT doc.*,\r\n\t\t substring(doc.\"MEDO_DETAIL\" FROM 'POSTALADDRESS=(.*?)\\|') as \"MEDO_ADDRESS\", \r\n\t\t medo_country.name as \"MEDO_COUNTRY\", \r\n\t\t doc_movement.\"PPID\" as \"DOCMOVEMENT_PPID\",\r\n\t\t country.name AS \"COUNTRY\" ,\r\n\t\t citizen.firstname AS
etc.

Tell me how to make the lines move to a new one, as I understand it, \r\n\t\t is a carriage translation, I.e. enter in a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-09-07
@vabka

JSON strings do not support line breaks within themselves, so CRLF is replaced with \r\n. if you make a conditional console.log(result[0].query), then it will be displayed as it should

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question