MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / ValidateRoutineOptions

Function ValidateRoutineOptions

pkg/sql/sem/tree/create_routine.go:652–704  ·  view source on GitHub ↗

ValidateRoutineOptions checks whether there are conflicting or redundant routine options in the given slice.

(options RoutineOptions, isProc bool)

Source from the content-addressed store, hash-verified

650// ValidateRoutineOptions checks whether there are conflicting or redundant
651// routine options in the given slice.
652func ValidateRoutineOptions(options RoutineOptions, isProc bool) error {
653 var hasLang, hasBody, hasLeakProof, hasVolatility, hasNullInputBehavior, hasSecurity bool
654 conflictingErr := func(opt RoutineOption) error {
655 return errors.Wrapf(ErrConflictingRoutineOption, "%s", AsString(opt))
656 }
657 for _, option := range options {
658 switch option.(type) {
659 case RoutineLanguage:
660 if hasLang {
661 return conflictingErr(option)
662 }
663 hasLang = true
664 case RoutineBodyStr:
665 if hasBody {
666 return conflictingErr(option)
667 }
668 hasBody = true
669 case RoutineLeakproof:
670 if isProc {
671 return pgerror.Newf(pgcode.InvalidFunctionDefinition, "leakproof attribute not allowed in procedure definition")
672 }
673 if hasLeakProof {
674 return conflictingErr(option)
675 }
676 hasLeakProof = true
677 case RoutineVolatility:
678 if isProc {
679 return pgerror.Newf(pgcode.InvalidFunctionDefinition, "volatility attribute not allowed in procedure definition")
680 }
681 if hasVolatility {
682 return conflictingErr(option)
683 }
684 hasVolatility = true
685 case RoutineNullInputBehavior:
686 if isProc {
687 return pgerror.Newf(pgcode.InvalidFunctionDefinition, "null input attribute not allowed in procedure definition")
688 }
689 if hasNullInputBehavior {
690 return conflictingErr(option)
691 }
692 hasNullInputBehavior = true
693 case RoutineSecurity:
694 if hasSecurity {
695 return conflictingErr(option)
696 }
697 hasSecurity = true
698 default:
699 return pgerror.Newf(pgcode.InvalidParameterValue, "unknown function option: ", AsString(option))
700 }
701 }
702
703 return nil
704}
705
706// GetRoutineVolatility tries to find a function volatility from the given list of
707// function options. If there is no volatility found, RoutineVolatile is

Callers

nothing calls this directly

Calls 2

NewfFunction · 0.92
AsStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…