Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Column header to lower case

I have a table with column names in upper case. I need to convert them to lower case, just the columns names alone and not the values inside them. Eg Table : Source Target (after converting to lower case)

ID  | NAME | AGE          id | name | age

1   | xxx       | 10              1 | xxx     | 10

2   | yyy       | 20              2 | yyy     | 20

I have used the below java code :

 

String columnName=null;
for (java.lang.reflect.Field field: row1.getClass().getDeclaredFields())
{
columnName=field.getName().toLowerCase();
System.out.println(columnName);

 

But this converts the column names to lower case but takes it as a value. the output for the above code is : id name age

Is there a way to convert the header to lower case and have the data as well?

Labels (3)
10 Replies
Anonymous
Not applicable
Author

I have a method that may speed things up a little, but it does require some familiarity with text editors and macros...

 

I was warehousing some salesforce objects into postgres and had the same problem. Some of the objects had many, many fields (100+ in some extreme cases) so it was not ideal to change each one manually.

 

First I synced the schema in the postgres output as normal. Then I selected edit schema , and on the right hand side of the popup window I selected the 'export all rows to xml' option.

 

I then opened the xml in a program called notepad++ (but you could also use other code/text editors with regular expression and macro features).

 

Using the find feature with this regular expression 

 (originalDbColumnName="\w*")

you can then record a macro which skips to each next match and sets the whole selection to lowercase.

 

 

Finally, I did a basic replace all on 'originaldbcolumnname' to convert it back to its original casing 'originalDbColumnName' (this is necessary because that part of the selection is the xml field name, which is case sensitive itself).

 

Saving the file and going back to the Talend window, I then selected the 'replace all rows from import by xml file' option. This will use the xml file where we just set everything to lowercase.

 

Obviously this is still a fiddly process, but if you have objects with over 50 fields it may help make things a little quicker and less prone to mistakes as you will not have to manually delete and retype the capital letters.