MCPcopy Create free account
hub / github.com/dolthub/doltgresql / resolveAlterColumn

Function resolveAlterColumn

server/analyzer/validate_create_table.go:153–328  ·  view source on GitHub ↗

resolveAlterColumn is a validation rule that validates the schema changes in an ALTER TABLE statement and updates the nodes with necessary intermediate / update schema information

(ctx *sql.Context, a *analyzer.Analyzer, n sql.Node, scope *plan.Scope, sel analyzer.RuleSelector, qFlags *sql.QueryFlags)

Source from the content-addressed store, hash-verified

151// resolveAlterColumn is a validation rule that validates the schema changes in an ALTER TABLE statement and updates
152// the nodes with necessary intermediate / update schema information
153func resolveAlterColumn(ctx *sql.Context, a *analyzer.Analyzer, n sql.Node, scope *plan.Scope, sel analyzer.RuleSelector, qFlags *sql.QueryFlags) (sql.Node, transform.TreeIdentity, error) {
154 if !analyzer.FlagIsSet(qFlags, sql.QFlagAlterTable) {
155 return n, transform.SameTree, nil
156 }
157
158 var sch sql.Schema
159 var indexes []string
160 var validator sql.SchemaValidator
161 keyedColumns := make(map[string]bool)
162 var err error
163 transform.Inspect(n, func(n sql.Node) bool {
164 if st, ok := n.(sql.SchemaTarget); ok {
165 sch = st.TargetSchema()
166 }
167 switch n := n.(type) {
168 case *plan.ModifyColumn:
169 if rt, ok := n.Table.(*plan.ResolvedTable); ok {
170 if sv, ok := rt.UnwrappedDatabase().(sql.SchemaValidator); ok {
171 validator = sv
172 }
173 }
174 keyedColumns, err = analyzer.GetTableIndexColumns(ctx, n.Table)
175 return false
176 case *plan.RenameColumn:
177 if rt, ok := n.Table.(*plan.ResolvedTable); ok {
178 if sv, ok := rt.UnwrappedDatabase().(sql.SchemaValidator); ok {
179 validator = sv
180 }
181 }
182 return false
183 case *plan.AddColumn:
184 if rt, ok := n.Table.(*plan.ResolvedTable); ok {
185 if sv, ok := rt.UnwrappedDatabase().(sql.SchemaValidator); ok {
186 validator = sv
187 }
188 }
189 keyedColumns, err = analyzer.GetTableIndexColumns(ctx, n.Table)
190 return false
191 case *plan.DropColumn:
192 if rt, ok := n.Table.(*plan.ResolvedTable); ok {
193 if sv, ok := rt.UnwrappedDatabase().(sql.SchemaValidator); ok {
194 validator = sv
195 }
196 }
197 return false
198 case *plan.AlterIndex:
199 if rt, ok := n.Table.(*plan.ResolvedTable); ok {
200 if sv, ok := rt.UnwrappedDatabase().(sql.SchemaValidator); ok {
201 validator = sv
202 }
203 }
204 indexes, err = analyzer.GetTableIndexNames(ctx, a, n.Table)
205 default:
206 }
207 return true
208 })
209
210 if err != nil {

Callers

nothing calls this directly

Calls 5

validateAlterIndexFunction · 0.85
validatePrimaryKeyFunction · 0.85
TargetSchemaMethod · 0.80
WithTargetSchemaMethod · 0.80
CopyMethod · 0.65

Tested by

no test coverage detected