Export CSV/TSV with multi-line text columns

Answered

Hello.

I'm trying to export a query from one server and import the result into another. The result contains a number of text columns with line breaks. When I export as either CSV or TSV, the line breaks are not escaped, and the resulting file is invalid.

I can export as JSON, in which case line breaks are correctly escaped, however DataGrip does not seem support data import from JSON.

What can I do in this case?

1
7 comments

What is the version of DataGrip? The issue with line endings should have been fixed in 2022.2
If it is still there, please share an example of such CSV

0

I am running DataGrip 2022.2.3 and have same issue with CSV export not quoting multiline fields

0

Paul Robello, is there a chance to share a CSV file? You can upload it to http://uploads.jetbrains.com/ and provide its ID.

0

I am currently experiencing this same issue with a database export on IntelliJ 2026.1
I have configured a tsv export with quotes on “When Needed” and when parsing the file discovered that it is invalid. It appears to me that the values are quoted when they have the field delimiter in them (tab), but not if they have the row delimiter (new line \n) in them.

0

Hi ItsMike,

It seems to work fine for me in the latest version. Do you see the same behavior in the preview before exporting the data? Could you please share a minimal sample TSV file?

0

Hi Anastasia Zhukova 
Regarding the preview, no because the preview isn't even showing the real data, but some placeholder example. The columns nor the values in the screenshot below exist in the sql I'm using to export data. If this was the actual data, it still wouldn't show though because the issue doesn't occur until much later in the large exports I'm doing. I did confirm that exporting with quotes “Always” does in fact create a valid tsv file.

 

## Minimal Reproducer Attempt
With the following dataset, I WAS NOT able to recreate the issue from the table view or executing a query from an SQL file and exporting to tsv file. With that in mind, my next guess is that it only happens when the data is large enough that the issue doesn't occur until past some amount of data IntelliJ may introspect or something like that. I can provide a larger data sample and table structure privately if you give me a means to do so. Please feel free to reach out to me.

```sql
create table test_tsv_export
(
    id         int auto_increment
        primary key,
    smallText  varchar(50)   not null,
    bigText    varchar(1000) not null,
    hasNewLine bool          not null
);

INSERT INTO datasets.test_tsv_export (smallText, bigText, hasNewLine) VALUES ('Simple Test', 'Easy one line', 0);
INSERT INTO datasets.test_tsv_export (smallText, bigText, hasNewLine) VALUES ('Slightly more complex', 'Another longer more complicated line, but no new lines or anything crazy.', 0);
INSERT INTO datasets.test_tsv_export (smallText, bigText, hasNewLine) VALUES ('Has New Line', 'This is a new line!
===================
Haha! Got you IntelliJ!', 1);
INSERT INTO datasets.test_tsv_export (smallText, bigText, hasNewLine) VALUES ('Another Simple Line', 'This line is simple again.', 0)
```

 

 

 

0

ItsMike,

I can provide a larger data sample and table structure privately if you give me a means to do so. Please feel free to reach out to me.

Would it be possible to upload the file privately to https://uploads.jetbrains.com/ and share the upload ID once it's done? You can post the ID here - uploaded files are only accessible to the JetBrains team.

0

Please sign in to leave a comment.