Skip to content

Recognize referential actions as keywords in ON UPDATE/DELETE #849

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

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

karlhorky
Copy link
Member

@karlhorky karlhorky commented Mar 24, 2025

Hi @nene, hope you're good! 👋

Currently, sql-formatter@15.5.1 does not recognize the PostgreSQL CASCADE, NO ACTION or RESTRICT referential actions as keywords.

This means that if identifiers are configured to be lowercased, the referential actions will be lower cased, eg. ON DELETE cascade:

CREATE TABLE orders (
  id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  customer_id integer REFERENCES customers (id) ON DELETE cascade
);

Screenshot 2025-03-24 at 16 31 07

This PR adjusts the reservedPhrases for PostgreSQL to add the CASCADE, NO ACTION and RESTRICT keywords as suffixes for ON UPDATE and ON DELETE.

Copy link

codesandbox-ci bot commented Mar 24, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@karlhorky karlhorky changed the title Recognize CASCADE as keyword in ON UPDATE/DELETE Recognize referential actions as keywords in ON UPDATE/DELETE Mar 24, 2025
@nene
Copy link
Collaborator

nene commented Mar 24, 2025

Thanks.

@nene nene merged commit 0b825e6 into sql-formatter-org:master Mar 24, 2025
2 checks passed
@nene
Copy link
Collaborator

nene commented Mar 26, 2025

Released in 15.5.2

@karlhorky
Copy link
Member Author

karlhorky commented Mar 26, 2025

Thanks for the review, merge and release!

I can confirm that sql-formatter@15.5.2 now formats the referential actions as keywords - eg. CASCADE now is uppercase, with keywordCase: 'upper':

CREATE TABLE orders (
  id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  customer_id integer REFERENCES customers (id) ON DELETE CASCADE
);

@nene
Copy link
Collaborator

nene commented Mar 26, 2025

Hey, I added you as a member of the sql-formatter-org "team".

@karlhorky
Copy link
Member Author

Oh wow, that's an honor, thank you! I will look to make more time to contribute here in the next months!

@nene
Copy link
Collaborator

nene commented Mar 26, 2025

That's great to hear ❤️

You should now have push access to the repository. Feel free to push directly any trivial changes. For larger changes and things you're not certain of, a pull request would be nice. Or you can also do a pull request that you then immediately merge by yourself, as a sort of "I'm letting you know I'm doing this". Use your own best judgement.

If you're missing some permissions, ping me.

@karlhorky
Copy link
Member Author

Yes, I think I'll probably do PRs for everything anyway, just as a way of communication to everyone 👍 Thanks!

@karlhorky karlhorky deleted the patch-1 branch March 26, 2025 09:04
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

Successfully merging this pull request may close these issues.

2 participants