- Newest
- Most votes
- Most comments
I understand you're encountering issues while unloading data from S3 to Redshift. Let's address both errors you've encountered:
-
"String Exceeds DDL Length": This error occurs when the data being loaded is longer than the column length defined in your table. In your case, changing the column to VARCHAR(256) didn't solve the issue, which suggests some of your data might be longer than 256 characters.
-
"String contains invalid or unsupported UTF8 codepoints": This error indicates that your data contains characters that are not valid UTF-8 encoded characters.
To resolve these issues, you can try the following:
-
Increase the VARCHAR length for columns that might contain longer data. For example, you could use VARCHAR(1000) or even VARCHAR(MAX) for columns that might contain very long strings.
-
Use the TRUNCATECOLUMNS option in your COPY command if you're okay with truncating data that exceeds the defined column length.
-
To handle the UTF-8 issue, you can use the ACCEPTINVCHARS option in your COPY command. This will replace invalid UTF-8 characters with a specified character.
Here's a modified version of your CREATE TABLE statement that increases some VARCHAR lengths:
CREATE TABLE demo_schema.sample_backbook_data ( ReferenceID varchar(256), LenderName varchar(256), UsageType varchar(256), NoticeFlag varchar(256), ExecutionDate varchar(20), IsOpenEnded varchar(256), EndDate varchar(20), CreditCategory varchar(256), AccountType varchar(256), FeeCategory varchar(256), LoanType varchar(256), StatusFlag varchar(256), EntityID varchar(256), EntityName varchar(256), AgreementType varchar(256), ManualFlag varchar(256), ServiceType varchar(256), AgreementOption varchar(256), FutureValueGuarantee varchar(256), AmendedFlag varchar(256), ProductBrand varchar(256), IsP2P varchar(256), CustomerType varchar(256), RefID varchar(256), CreditRecipientName varchar(1000), NumberOfEntities integer, CustomerID varchar(256), CustomerDOB date, CollateralType varchar(256), GuarantorFlag varchar(256), GuarantorID varchar(256), GuarantorDOB varchar(20), TotalAmount numeric(18,2), TotalCharges numeric(18,2), APR numeric(18,2) );
Then, when using the COPY command to load data, include the TRUNCATECOLUMNS and ACCEPTINVCHARS options:
COPY demo_schema.sample_backbook_data FROM 's3://your-bucket/your-file.csv' CREDENTIALS 'aws_iam_role=your-iam-role' CSV TRUNCATECOLUMNS ACCEPTINVCHARS AS '?';
These modifications should help resolve both the string length and UTF-8 encoding issues you're experiencing. If you're using a stored procedure to load the data, you may need to modify it to include these options.
Sources
Troubleshoot S3 ingestion into Redshift | AWS re:Post
Tutorial: Using spatial SQL functions with Amazon Redshift - Amazon Redshift
answered a year ago
