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

[FORMATTING] REPLACE Not Properly Uppercased in PostgreSQL Dialect #813

Closed
etzelc opened this issue Dec 23, 2024 · 3 comments
Closed

[FORMATTING] REPLACE Not Properly Uppercased in PostgreSQL Dialect #813

etzelc opened this issue Dec 23, 2024 · 3 comments
Labels

Comments

@etzelc
Copy link

etzelc commented Dec 23, 2024

When using the PostgreSQL dialect with the following configuration:

{
  "language": "postgresql",
  "dialect": "postgresql",
  "tabWidth": 2,
  "keywordCase": "upper",
  "dataTypeCase": "lower",
  "functionCase": "lower",
  "identifierCase": "lower",
  "expressionWidth": 80,
  "linesBetweenQueries": 1
}

The formatter incorrectly converts REPLACE to lowercase (replace) even though keywordCase is set to "upper".

This happens since the upgrade from 15.4.7 to 15.4.8.

Input data

CREATE
OR REPLACE function empty_function () returns void AS $$
BEGIN
  -- Do nothing
END;
$$ language plpgsql;

Expected Output

CREATE
OR REPLACE function empty_function () returns void AS $$
BEGIN
  -- Do nothing
END;
$$ language plpgsql;

Actual Output

CREATE
OR replace function empty_function () returns void AS $$
BEGIN
  -- Do nothing
END;
$$ language plpgsql;
@etzelc etzelc added the bug label Dec 23, 2024
@nene
Copy link
Collaborator

nene commented Dec 23, 2024

Thanks for reporting.

The issue is that the formatter doesn't recognize OR REPLACE as part of CREATE FUNCTION.

Also I should point out the following:

  • Using "dialect": "postgresql" has no effect when language option is also present. If anything it might lead to a crash in the future, as strings are not valid values for the dialect option. Really, the dialect option does the same as the language option. But it makes no sense to use it in config file - only when calling the library through code.
  • The identifierCase option is experimental and will result in lots of keywords being converted to lowercase. Really the only time to use it would be when you either want all of the code to be in either lower- or uppercase. Or at least, I wouldn't use it. Though if you're happy with the result, feel free to use it.

nene added a commit that referenced this issue Dec 23, 2024
@nene nene closed this as completed Dec 23, 2024
@etzelc
Copy link
Author

etzelc commented Dec 23, 2024

Thank you for your feedback on the config file. I’ll test your suggestions.

And a big thanks for resolving the issue so quickly! 👍

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

No branches or pull requests

3 participants
@nene @etzelc and others