CartoDB / CartoDB-SQL-API

CartoDB SQL API
BSD 3-Clause "New" or "Revised" License
63 stars 65 forks source link

Log pg copy to warnings #594

Closed rafatower closed 5 years ago

rafatower commented 5 years ago

Related to https://github.com/CartoDB/node-pg-copy-streams/pull/9

Tested with the same test function that raises a warning, got the following result now:

$ QUERY="COPY+(SELECT+*+FROM+test_return_one())+to+STDOUT+WITH+(FORMAT+'csv',+HEADER+true)"
$ curl --output - "${BASE_URL}/api/v1/sql/copyto?api_key=${API_KEY}&q=${QUERY}"
test_return_one
1

and in the copy logs:

{"name":"data-ingestion","hostname":"carto-rtorre","pid":31254,"level":40,"msg":"Got an interspersed message: SWARNING\u0000VWARNING\u0000C01000\u0000Mhey, this is returning one\u0000WPL/pgSQL function test_return_one() line 3 at RAISE\u0000Fpl_exec.c\u0000L3337\u0000Rexec_stmt_raise\u0000\u0000","time":"2019-06-04T17:12:32+0200","v":0}
{"name":"data-ingestion","hostname":"carto-rtorre","pid":31254,"level":30,"type":"copyto","format":"TEXT","size":18,"rows":2,"gzip":false,"cdb-user":"development","time":0.002,"timestamp":"2019-06-04T15:12:32.315Z","sql":"COPY (SELECT * FROM test_return_one()) to STDOUT WITH (FORMAT 'csv', HEADER true)","success":true,"msg":"","v":0}