Allow uppercasing of function names separately from keywords
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:
- SQLFormat has options for keyword and identifier case
- Instant SQL Formatter has 9 options for various language elements.
- Freeformatter.com has options for keyword and identifier case
- SQL Complete has options for separate casing of alias, function, data-type, identifier, keyword, variable.
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 andUPDATE table SET age = 10 WHERE name = 'John'; -
CAST(1 AS INT)casting function andRETURNS INT CAST FROM FLOAT -
SELECT ANY(age>10)aggregate function andSELECT * 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.
There is also the reverse case: some functions do not require parentheses: ie. CURRENT_DATE, TIMESTAMP, etc.
functionCase would be a great addition to this already awesome project! It just looks strange to me too see PostgreSQL functions in uppercase.
Ah this is also closed by my PR for dataTypeCase (uppercasing + lowercasing for data types) + functionCase:
- #673