CSV files refuse to open on redshift. What to do?

Hi everyone here. Need your help.

I’m currently working on a project that seeks to collect all the data regarding my shop on Amazon. The goal is to increase the accountability level because I have suffered a serious decline in clients in the past few months. It was an exhausting process but the goal seems to be worthy. I was working with both Excel and an accounting program that I generally use, and haven’t faced any problems until that day. I need to download the files into amazon redshift, but something doesn’t want me to do so.

I have some problems with loading CSV files into amazon redshift. Don’t know what happens but the file simply refuses to be implemented correctly. It changes all the values if the CSV file has carriage returns. I checked the files using other programs but haven’t noticed any issues with it. So, it means that the problem is in redshift itself. I tried to resolve the problem using the guide on https://aws.amazon.com/premiumsupport/knowledge-center/redshift-copy-nothing-loaded/ but eventually failed to fix the problem. At the same time, I found on https://www.import2.com/csv some practical guidelines that helped me to understand the issue a little bit more. I tried to make different format changes to these CSV files, but still no luck. Maybe, there is a combination of issues both with these files and redshift because there are no issues with them separately. Maybe the market gods simply don’t want me to make business, lol?

Have anyone faced here the same problems trying to import CSV files into redshift? I need to finish my work as soon as possible, so your help would be highly appreciated. Any suggestions?

You should really post an example of the copy command you use if you want us to help.

Is the file separated by `|` instead of `,` as is the default in redshift?

Generally speaking when I’m new to a commercial service that has been around for a while and I encounter an error, it is usually because:

A) I didn’t read some nuanced documentation

B) I didn’t search Stackoverflow

C) I’m having a stupid day

D) All of the above.

I don’t know anything about redshift, but the usual problems with csv are:

  1. Line endings
  2. Encoding (unicode vs other)
  3. Quotations in the data not properly escaped
  4. Carriage returns in the data not properly escaped
  5. Header vs no-header
  6. Leading spaces

lol what the frick

We’re basically just going to have to guess unless you give us a small sample that doesn’t work as expected and explain the steps that you did.

Yes, if you don’t specify the delimiter keyword in your load command redshift uses pipe character as delimiter. So just thinking it might be the issue in this case.

wonder why redshift team decided PSV (pipe separators value) files were the way to go

In your COPY command, there a number of parameters that you will likely need to set. Here is the documentation. You should read through each one, figure out if it applies to your situation, and if so, what you set there. For a true CSV (Redshift defaults to pipe-separated), this is usually an OK place to start:

COPY my_table
FROM ‘s3://my-bucket/my/prefix/’
IAM_ROLE ‘’
DELIMITER AS ‘,’
BLANKSASNULL
TRUNCATECOLUMNS
IGNOREHEADER 1
CSV;

Edit: If your csv files have carriage return as the line termination character, then this will not work. Per the documentation, you’ll need to replace the file with either CRLF (\r\n) or LF (\n).

yeah, one can wonder. probably some performance reason when loading massive amounts of data into postgres.

Using a mac? Using Excel? The mac version of Excel doesn’t use the “normal” end of line character (\n) and uses carriage returns (\r). Redshift doesn’t really know about that…b/c no one else uses that. You can save your file using a different format in Excel to avoid this nonsense, just look around the various “.csv” options.

yeah i wonder if they basically assumed that more commas would mean more backslashes

Also separator characters

Anything in the stl_load_errors? or does it just not load?

Because commas are very problematic default delimiters when parsing numbers.

5,25 is a valid representation of five and a quarter in a fair few countries.

Ding ding ding ding!

Check stl_load_errors and see if it’s logging anything. If it’s not then it actually appears to be loading data even though it’s not (seems highly unlikely). If you’ve got something wrong with anything (column list, data types, column delimiter, line endings, file types, etc.) it’ll show up in that system view for load errors.

If it’s “loading” aka no errors, but your table is empty then that tells me your s3 file is empty.

I wish I read this response a month ago…