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

Allow uppercasing of function names separately from keywords #237

Closed
nene opened this issue Jun 13, 2022 · 4 comments · Fixed by #673
Closed

Allow uppercasing of function names separately from keywords #237

nene opened this issue Jun 13, 2022 · 4 comments · Fixed by #673
Labels

Comments

@nene
Copy link
Collaborator

nene commented Jun 13, 2022

Currently we have a single option keywordCase which specifies the case for both keywords and function names.

It would be nice to allow more fine-grained control by having a separate option functionCase to control whether function names should be uppercased or lowercased. It's quite common practice when writing SQL to have different case-convention for the keywords and function names. Most commonly uppercasing keywords and lowercasing function names, like:

SELECT
  round(price * abs(tax)) AS final_price
FROM
  inventory;

This feature is also widespread in many other SQL formatting tools:

@nene nene added the feature label Jun 13, 2022
@nene
Copy link
Collaborator Author

nene commented Jun 13, 2022

The initial most obvious solution I had in my head was to distinguish them solely by name, but this won't work as some function name are also keywords used elsewhere in SQL. For example:

  • SET() function and UPDATE table SET age = 10 WHERE name = 'John';
  • CAST(1 AS INT) casting function and RETURNS INT CAST FROM FLOAT
  • SELECT ANY(age>10) aggregate function and SELECT * FROM foo WHERE ProductID = ANY (SELECT id FROM tbl)

Luckily these are fairly rare cases. But still.

Another option would be to look whether function name is followed by open-parenthesis (. This seems more promising, though one has to keep in mind that not every name followed by parenthesis is a function.

@inferrinizzard
Copy link
Collaborator

There is also the reverse case: some functions do not require parentheses: ie. CURRENT_DATE, TIMESTAMP, etc.

@jacobsvante
Copy link

functionCase would be a great addition to this already awesome project! It just looks strange to me too see PostgreSQL functions in uppercase.

@karlhorky
Copy link
Contributor

karlhorky commented Dec 5, 2023

Ah this is also closed by my PR for dataTypeCase (uppercasing + lowercasing for data types) + functionCase:

@nene nene closed this as completed in #673 Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants