-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
plpgsql: add support for CONSTANT variable declarations #107682
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 3 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @chengxiong-ruan, @DrewKimball, and @rharding6373)
pkg/sql/opt/optbuilder/create_function.go
line 250 at r1 (raw file):
stmtScope = plBuilder.build(stmt.AST, bodyScope) }) checkStmtVolatility(targetVolatility, stmtScope, stmt)
Can you add tests for mismatched volatility, if they don't already exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool.
This patch ensures that PLpgSQL functions are built during function creation, not just during invocation. This ensures that compile-time errors are thrown when the function is created. This commit also tests and corrects the codes for some of the errors that can be thrown while building a PLpgSQL function. Note that some of the existing tests had to be removed since they called UDFs within other UDFs. We didn't catch this before because the restriction is only checked during function creation when the body statements are first built. Fixes cockroachdb#107681 Release note: None
It is possible to declare variables as CONSTANT in PLpgSQL. This will cause any attempt to assign to the variable to result in a compile-time error. This patch implements CONSTANT variables by adding a check whenever an assignment is built that the assigned variable is non-constant. Fixes cockroachdb#105241 Release note (sql change): Added support for CONSTANT variable declarations in PLpgSQL routines. Any assignment to a variable declared with the CONSTANT keyword will raise a compile-time error.
a04d27f
to
a181794
Compare
TFTRs! bors r+ |
Build succeeded: |
plpgsql: validate PLpgSQL functions during creation
This patch ensures that PLpgSQL functions are built during function
creation, not just during invocation. This ensures that compile-time
errors are thrown when the function is created. This commit also tests
and corrects the codes for some of the errors that can be thrown while
building a PLpgSQL function.
Note that some of the existing tests had to be removed since they called
UDFs within other UDFs. We didn't catch this before because the restriction
is only checked during function creation when the body statements are first
built.
Fixes #107681
Release note: None
plpgsql: add support for CONSTANT variable declarations
It is possible to declare variables as CONSTANT in PLpgSQL. This will cause
any attempt to assign to the variable to result in a compile-time error.
This patch implements CONSTANT variables by adding a check whenever an
assignment is built that the assigned variable is non-constant.
Fixes #105241
Release note (sql change): Added support for CONSTANT variable
declarations in PLpgSQL routines. Any assignment to a variable declared
with the CONSTANT keyword will raise a compile-time error.