Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple usage - formatting Function Keywords #435

Open
psychemedia opened this issue Oct 1, 2018 · 2 comments
Open

Simple usage - formatting Function Keywords #435

psychemedia opened this issue Oct 1, 2018 · 2 comments

Comments

@psychemedia
Copy link

psychemedia commented Oct 1, 2018

Hi

I seem to be misunderstanding s/thing about usage. Running:

import sqlparse
sqlparse.format("select * from count(x);", keyword_case='upper')

I get the output:

'SELECT * FROM count(x);'

Terms of the form keyword() do not get uppercased, whereas I'd expect them to (I see them listed as keywords in the code?)?

Is this something to do with the tokeniser getting upset by the brackets? Things seem to work if the brackets are escaped?

import re
x=sqlparse.format(re.escape("select * from max(count(x));"), keyword_case='upper')
re.sub(r'\\(.)', r'\1', x)

#>> SELECT * FROM MAX(COUNT(x));
@psychemedia psychemedia changed the title Simple usage - formatting Keywords Simple usage - formatting Function Keywords Oct 1, 2018
@janurag
Copy link

janurag commented Dec 12, 2018

Same kind of issue happening with me
SELECT coalesce(date_format(be.publish_datetime,'%m-%d-%Y'),' ') AS Published_Date, COALESCE(DATE_FORMAT(bh.Awarded_Date,'%m-%d-%Y'),' ') AS Awarded_Date,
Above is the output i got. Ideally i was expecting coalesce to be converted to upper case.

Is there a proper way that i can do this? @andialbrecht
Note: Tried diving into the code but i am beginner in python, hence the code was overwhelming for me.

@raybuhr
Copy link

raybuhr commented Jan 16, 2019

function case can be set with the option identifier_case that works the same as keyword_case. for example,

sql_options = {
    'keyword_case': 'upper',
    'identifier_case': 'upper',
}

would set both keywords and functions to upper case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants