0

I am new to postgresql and just starting to use it. I am trying to load a file into a table and facing some issues.

Sample data - the file file1.RPT contains data in the below format

"Bharath"|Kumar|Krishnan
 abc"|def|ghi
 qwerty|asdfgh|lkjhg

Below is the load script that is used

LOAD CSV
INTO table1
....
WITH truncate,
fields optionally enclosed by '"',
fields escaped by '"'
fields terminated by '|'
....

However, the above script is not working and is not loading any data into the table. I am not sure whats the issue here. My understanding is that first row data has to be successfully loaded (since I have given optionally enclosed by) and the second row also must be loaded (since I am trying to escape the double quote).

Request help in getting the same rectified.

Thank you.

Bharath
  • 56
  • 1
  • 5

2 Answers2

0

We cannot escape and optionally quote the same character. If the double-quote will be part of the data, then it can be ignored using field not enclosed option. The default option is field optionally enclosed by double-quote.

Bharath
  • 56
  • 1
  • 5
0

Apparently, you're not escaping the quote in the second row, because either you must use a backslash (or another quoting character) before:

abc\"|def|ghi

or you should enclose the entire line with quote

another alternative is to accept to have quotes in the first field, then you should use the following:

fields not enclosed

in your load script