Postgresql: CSV export with escaped linebreaks

后端 未结 1 1718
心在旅途
心在旅途 2021-01-18 20:01

I exported some data from a postgresql database using (all) the instruction(s) posted here: Save PL/pgSQL output from PostgreSQL to a CSV file

But some exported fiel

相关标签:
1条回答
  • 2021-01-18 20:53

    Line breaks are supported in CSV if the fields that contain them are enclosed in double quotes.

    So if you had this in the middle of the file:

    just another value;f*** value;"value with
    newline"
    

    it will be taken as 1 line of data spread on 2 lines with 3 fields and just work.

    On the other hand, without the double quotes, it's an invalid CSV file (when it advertises 3 fields).

    Although there's no formal specification for the CSV format, you may look at RFC 4180 for the rules that generally apply.

    0 讨论(0)
提交回复
热议问题