(stmt *ast.ViewStmt, colGen columnGenerator)
| 6 | ) |
| 7 | |
| 8 | func (c *Catalog) createView(stmt *ast.ViewStmt, colGen columnGenerator) error { |
| 9 | cols, err := colGen.OutputColumns(stmt.Query) |
| 10 | if err != nil { |
| 11 | return err |
| 12 | } |
| 13 | |
| 14 | catName := "" |
| 15 | if stmt.View.Catalogname != nil { |
| 16 | catName = *stmt.View.Catalogname |
| 17 | } |
| 18 | schemaName := "" |
| 19 | if stmt.View.Schemaname != nil { |
| 20 | schemaName = *stmt.View.Schemaname |
| 21 | } |
| 22 | |
| 23 | tbl := Table{ |
| 24 | Rel: &ast.TableName{ |
| 25 | Catalog: catName, |
| 26 | Schema: schemaName, |
| 27 | Name: *stmt.View.Relname, |
| 28 | }, |
| 29 | Columns: cols, |
| 30 | } |
| 31 | |
| 32 | ns := tbl.Rel.Schema |
| 33 | if ns == "" { |
| 34 | ns = c.DefaultSchema |
| 35 | } |
| 36 | schema, err := c.getSchema(ns) |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | _, existingIdx, err := schema.getTable(tbl.Rel) |
| 41 | if err == nil && !stmt.Replace { |
| 42 | return sqlerr.RelationExists(tbl.Rel.Name) |
| 43 | } |
| 44 | |
| 45 | if stmt.Replace && err == nil { |
| 46 | schema.Tables[existingIdx] = &tbl |
| 47 | } else { |
| 48 | schema.Tables = append(schema.Tables, &tbl) |
| 49 | } |
| 50 | |
| 51 | return nil |
| 52 | } |
no test coverage detected