sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Incorrect Case formatting

Open minatverma opened this issue 10 years ago • 6 comments

In the Keywords.py file current_timestamp , sum etc are mapped as Keywords. Using sqplarse doesnot change its case to uppercase while using Upper clause in the syntax.

minatverma avatar Nov 12 '14 08:11 minatverma

Could you provide an example?

andialbrecht avatar Nov 30 '14 05:11 andialbrecht

Formatting : SELECT MAX(D_Fiscal_period) FROM mip.mip_filter_period WHERE D_Sales_data_type IN ('SELL-IN') AND D_Period_type_desc IN ('Quarter')

Gave the result

SELECT max(d_fiscal_period) FROM mip.mip_filter_period WHERE d_sales_data_type IN ('SELL-IN') AND d_period_type_desc IN ('Quarter')

Every things okay here except I am getting MAX() case being lowered. Is this because it is associated with () whose case cannot be determined ? I am using below settings : file = open(outfile, 'w').write(sqlparse.format(sql_array, reindent=True,indent_width = 4, keyword_case='upper', identifier_case = 'lower')) Let me know if I am missing something here.

minatverma avatar Dec 02 '14 09:12 minatverma

Yes, that's because of the parentheses. It counts as a function call, but not as a keyword in that case.

Minat Kumar Verma [email protected] schrieb am Tue Dec 02 2014 at 10:36:54:

Formatting : SELECT MAX(D_Fiscal_period) FROM mip.mip_filter_period WHERE D_Sales_data_type IN ('SELL-IN') AND D_Period_type_desc IN ('Quarter')

Gave the result

SELECT max(d_fiscal_period) FROM mip.mip_filter_period WHERE d_sales_data_type IN ('SELL-IN') AND d_period_type_desc IN ('Quarter')

Every things okay here except I am getting MAX() case being lowered. Is this because it is associated with () whose case cannot be determined ? I am using below settings : file = open(outfile, 'w').write(sqlparse.format(sql_array, reindent=True,indent_width = 4, keyword_case='upper', identifier_case = 'lower')) Let me know if I am missing something here.

Reply to this email directly or view it on GitHub https://github.com/andialbrecht/sqlparse/issues/150#issuecomment-65204272 .

andialbrecht avatar Dec 02 '14 11:12 andialbrecht

Any work around can you suggest to overcome this ?

minatverma avatar Dec 02 '14 11:12 minatverma

you can use the option identifier_case to format functions similar to keyword_case.

raybuhr avatar Jan 16 '19 00:01 raybuhr

This was the response on another issue as well. How can you get keywords and functions to be all caps, but not column names? identifier_case also affects column names.

benjaminkaplanphd avatar Sep 28 '20 19:09 benjaminkaplanphd