parseCreateView parses CREATE [OR REPLACE] [TEMPORARY] VIEW statement
(orReplace, temporary bool)
| 25 | |
| 26 | // parseCreateView parses CREATE [OR REPLACE] [TEMPORARY] VIEW statement |
| 27 | func (p *Parser) parseCreateView(orReplace, temporary bool) (*ast.CreateViewStatement, error) { |
| 28 | stmt := &ast.CreateViewStatement{ |
| 29 | OrReplace: orReplace, |
| 30 | Temporary: temporary, |
| 31 | } |
| 32 | |
| 33 | // Check for IF NOT EXISTS |
| 34 | if p.isType(models.TokenTypeIf) { |
| 35 | p.advance() // Consume IF |
| 36 | if !p.isType(models.TokenTypeNot) { |
| 37 | return nil, p.expectedError("NOT after IF") |
| 38 | } |
| 39 | p.advance() // Consume NOT |
| 40 | if !p.isType(models.TokenTypeExists) { |
| 41 | return nil, p.expectedError("EXISTS after NOT") |
| 42 | } |
| 43 | p.advance() // Consume EXISTS |
| 44 | stmt.IfNotExists = true |
| 45 | } |
| 46 | |
| 47 | // Parse view name (supports schema.view qualification and double-quoted identifiers) |
| 48 | viewName, err := p.parseQualifiedName() |
| 49 | if err != nil { |
| 50 | return nil, p.expectedError("view name") |
| 51 | } |
| 52 | stmt.Name = viewName |
| 53 | |
| 54 | // Parse optional column list |
| 55 | if p.isType(models.TokenTypeLParen) { |
| 56 | p.advance() // Consume ( |
| 57 | for { |
| 58 | if !p.isIdentifier() { |
| 59 | return nil, p.expectedError("column name") |
| 60 | } |
| 61 | stmt.Columns = append(stmt.Columns, p.currentToken.Token.Value) |
| 62 | p.advance() |
| 63 | |
| 64 | if p.isType(models.TokenTypeComma) { |
| 65 | p.advance() // Consume comma |
| 66 | continue |
| 67 | } |
| 68 | break |
| 69 | } |
| 70 | if !p.isType(models.TokenTypeRParen) { |
| 71 | return nil, p.expectedError(")") |
| 72 | } |
| 73 | p.advance() // Consume ) |
| 74 | } |
| 75 | |
| 76 | // Expect AS |
| 77 | if !p.isType(models.TokenTypeAs) { |
| 78 | return nil, p.expectedError("AS") |
| 79 | } |
| 80 | p.advance() // Consume AS |
| 81 | |
| 82 | // Parse the SELECT statement |
| 83 | if !p.isType(models.TokenTypeSelect) { |
| 84 | return nil, p.expectedError("SELECT") |
no test coverage detected