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

Method Format

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

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

94
95// Format implements the NodeFormatter interface.
96func (node *CreateRoutine) Format(ctx *FmtCtx) {
97 ctx.WriteString("CREATE ")
98 if node.Replace {
99 ctx.WriteString("OR REPLACE ")
100 }
101 if node.IsProcedure {
102 ctx.WriteString("PROCEDURE ")
103 } else {
104 ctx.WriteString("FUNCTION ")
105 }
106 ctx.FormatNode(&node.Name)
107 ctx.WriteByte('(')
108 ctx.FormatNode(node.Params)
109 ctx.WriteString(")\n\t")
110 if !node.IsProcedure && node.ReturnType != nil {
111 ctx.WriteString("RETURNS ")
112 if node.ReturnType.SetOf {
113 ctx.WriteString("SETOF ")
114 }
115 ctx.FormatTypeReference(node.ReturnType.Type)
116 ctx.WriteString("\n\t")
117 }
118 var isPLpgSQL bool
119 var funcBody RoutineBodyStr
120 for _, option := range node.Options {
121 switch t := option.(type) {
122 case RoutineBodyStr:
123 funcBody = t
124 continue
125 case RoutineLeakproof, RoutineVolatility, RoutineNullInputBehavior:
126 if node.IsProcedure {
127 continue
128 }
129 case RoutineLanguage:
130 isPLpgSQL = t == RoutineLangPLpgSQL
131 }
132 ctx.FormatNode(option)
133 ctx.WriteString("\n\t")
134 }
135
136 if ctx.HasFlags(FmtMarkRedactionNode) {
137 ctx.WriteString("AS ")
138 ctx.WriteString("$$")
139 for i, stmt := range node.BodyStatements {
140 if i > 0 {
141 ctx.WriteByte(' ')
142 }
143 ctx.WithAnnotations(node.BodyAnnotations[i], func() {
144 ctx.FormatNode(stmt)
145 if !isPLpgSQL {
146 // PL/pgSQL statements handle printing semicolons themselves.
147 ctx.WriteByte(';')
148 }
149 })
150 }
151 ctx.WriteString("$$")
152 } else if node.RoutineBody != nil {
153 ctx.WriteString("BEGIN ATOMIC ")

Callers

nothing calls this directly

Calls 4

FormatNodeMethod · 0.80
FormatTypeReferenceMethod · 0.80
WithAnnotationsMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected