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

New Rule: use CREATE OR REPLACE #35

Closed
silviomarghitola opened this issue Jun 3, 2019 · 4 comments
Closed

New Rule: use CREATE OR REPLACE #35

silviomarghitola opened this issue Jun 3, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@silviomarghitola
Copy link

** Language Usage / Stored Objects / General**
always use CREATE OR REPLACE instead of only CREATE

@PhilippSalvisberg
Copy link
Collaborator

from SonarSource:

"CREATE OR REPLACE" should be used instead of "CREATE"

When creating a function, procedure, package, package body, type, type body, trigger or library, it is a good practice replace the existing one to avoid errors.

Noncompliant Code Example

CREATE FUNCTION my_function RETURN PLS_INTEGER AS -- Noncompliant
BEGIN
  RETURN 42;
END;
/

Compliant Solution

CREATE OR REPLACE FUNCTION my_function RETURN PLS_INTEGER AS -- Compliant, no error even if the function already exists
BEGIN
  RETURN 42;
END;
/

@PhilippSalvisberg
Copy link
Collaborator

I tend to agree. The question is: does someone uses create without replace by purpose? E.g. to ensure the statement fails on second execution? Thoughts?

@PhilippSalvisberg PhilippSalvisberg added enhancement New feature or request help wanted Extra attention is needed labels Jun 4, 2019
@S-Koell
Copy link

S-Koell commented Mar 5, 2020

I would think that a create without a replace is so niche that this rule would make sense.
Because the persons knows what he is doing if he leaves out the "replace" and therefore can ignore that rule easily.
And if a "replace" is forgotten it can lead to problems.

I vote for this rule.

@PhilippSalvisberg
Copy link
Collaborator

Thanks, so let's add this rule.

@PhilippSalvisberg PhilippSalvisberg removed the help wanted Extra attention is needed label Mar 5, 2020
@kibeha kibeha self-assigned this Sep 23, 2020
@kibeha kibeha added this to the v4.0 milestone Sep 23, 2020
@kibeha kibeha closed this as completed in c25b7e2 Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants