parseCreateMaterializedView parses CREATE MATERIALIZED VIEW statement
()
| 132 | |
| 133 | // parseCreateMaterializedView parses CREATE MATERIALIZED VIEW statement |
| 134 | func (p *Parser) parseCreateMaterializedView() (*ast.CreateMaterializedViewStatement, error) { |
| 135 | stmt := &ast.CreateMaterializedViewStatement{} |
| 136 | |
| 137 | // Check for IF NOT EXISTS |
| 138 | if p.isType(models.TokenTypeIf) { |
| 139 | p.advance() // Consume IF |
| 140 | if !p.isType(models.TokenTypeNot) { |
| 141 | return nil, p.expectedError("NOT after IF") |
| 142 | } |
| 143 | p.advance() // Consume NOT |
| 144 | if !p.isType(models.TokenTypeExists) { |
| 145 | return nil, p.expectedError("EXISTS after NOT") |
| 146 | } |
| 147 | p.advance() // Consume EXISTS |
| 148 | stmt.IfNotExists = true |
| 149 | } |
| 150 | |
| 151 | // Parse view name (supports schema.view qualification and double-quoted identifiers) |
| 152 | matViewName, err := p.parseQualifiedName() |
| 153 | if err != nil { |
| 154 | return nil, p.expectedError("materialized view name") |
| 155 | } |
| 156 | stmt.Name = matViewName |
| 157 | |
| 158 | // Parse optional column list |
| 159 | if p.isType(models.TokenTypeLParen) { |
| 160 | p.advance() // Consume ( |
| 161 | for { |
| 162 | if !p.isIdentifier() { |
| 163 | return nil, p.expectedError("column name") |
| 164 | } |
| 165 | stmt.Columns = append(stmt.Columns, p.currentToken.Token.Value) |
| 166 | p.advance() |
| 167 | |
| 168 | if p.isType(models.TokenTypeComma) { |
| 169 | p.advance() // Consume comma |
| 170 | continue |
| 171 | } |
| 172 | break |
| 173 | } |
| 174 | if !p.isType(models.TokenTypeRParen) { |
| 175 | return nil, p.expectedError(")") |
| 176 | } |
| 177 | p.advance() // Consume ) |
| 178 | } |
| 179 | |
| 180 | // Parse optional TABLESPACE |
| 181 | if p.isTokenMatch("TABLESPACE") { |
| 182 | p.advance() // Consume TABLESPACE |
| 183 | if !p.isIdentifier() { |
| 184 | return nil, p.expectedError("tablespace name") |
| 185 | } |
| 186 | stmt.Tablespace = p.currentToken.Token.Value |
| 187 | p.advance() |
| 188 | } |
| 189 | |
| 190 | // Expect AS |
| 191 | if !p.isType(models.TokenTypeAs) { |
no test coverage detected