Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift Unload with case-sensitive headers

Previously, unload command did not create header row. This functionality is now available with "HEADER" option. However, it does not preserve the case of the headers.

The following statement creates a file with header "my column header 1"...

UNLOAD ('SELECT col1 "My Column Header 1", col2 "My Column Header 2" FROM mytable;')  
TO 's3://mybucket/filename.csv.'  
CREDENTIALS 'aws_iam_role=mycredentials'  
DELIMITER ','  
HEADER  
ALLOWOVERWRITE 
ADDQUOTES  
PARALLEL OFF;

Is there a way to preserve case in column headings?

like image 405
Noor Avatar asked Feb 07 '26 04:02

Noor


2 Answers

Modify the Redshift server configuration using SET property

enable_case_sensitive_identifier - A configuration value that determines whether name identifiers of databases, tables, and columns are case sensitive

SET enable_case_sensitive_identifier TO true;
SELECT or CREATE TABLE
RESET enable_case_sensitive_identifier;

https://docs.aws.amazon.com/redshift/latest/dg/t_Modifying_the_default_settings.html

like image 177
Rajish sani Avatar answered Feb 09 '26 08:02

Rajish sani


No there is no way to do that when using the HEADER option, because Redshift does not have case sensitive column names. All identifiers (table names, column names etc.) are always stored in lower case in the Redshift metadata.

You can optionally set a parameter so that column names are all returned as upper case in the results of a SELECT statement.

https://docs.aws.amazon.com/redshift/latest/dg/r_names.html

ASCII letters in standard and delimited identifiers are case-insensitive and are folded to lowercase in the database. In query results, column names are returned as lowercase by default. To return column names in uppercase, set the describe_field_name_in_uppercase configuration parameter to true.

like image 22
Nathan Griffiths Avatar answered Feb 09 '26 08:02

Nathan Griffiths



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!