Reputation: 165
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?
Upvotes: 3
Views: 3888
Reputation: 486
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
Upvotes: 3
Reputation: 12756
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.
Upvotes: 1