(pos Pos)
| 511 | } |
| 512 | |
| 513 | func (p *Parser) parseTableSchemaClause(pos Pos) (*TableSchemaClause, error) { |
| 514 | switch { |
| 515 | case p.matchTokenKind(TokenKindLParen): |
| 516 | // parse column definitions |
| 517 | if err := p.expectTokenKind(TokenKindLParen); err != nil { |
| 518 | return nil, err |
| 519 | } |
| 520 | |
| 521 | columns, err := p.parseTableColumns() |
| 522 | if err != nil { |
| 523 | return nil, err |
| 524 | } |
| 525 | |
| 526 | rightParenPos := p.Pos() |
| 527 | if err := p.expectTokenKind(TokenKindRParen); err != nil { |
| 528 | return nil, err |
| 529 | } |
| 530 | return &TableSchemaClause{ |
| 531 | SchemaPos: pos, |
| 532 | SchemaEnd: rightParenPos, |
| 533 | Columns: columns, |
| 534 | }, nil |
| 535 | case p.matchKeyword(KeywordAs) && !p.peekKeyword(KeywordSelect) && !p.peekKeyword(KeywordWith) && !p.peekTokenKind(TokenKindLParen): |
| 536 | // Handle AS only if followed by identifier (not SELECT/WITH/LPAREN) |
| 537 | // This handles: AS ident, AS ident.ident, AS ident(...) |
| 538 | // CREATE TABLE will handle: AS SELECT, AS WITH, AS (SELECT ...) |
| 539 | p.tryConsumeKeywords(KeywordAs) |
| 540 | |
| 541 | ident, err := p.parseIdent() |
| 542 | if err != nil { |
| 543 | return nil, err |
| 544 | } |
| 545 | switch { |
| 546 | case p.matchTokenKind(TokenKindDot): |
| 547 | // it's a database.table |
| 548 | dotIdent, err := p.tryParseDotIdent(p.Pos()) |
| 549 | if err != nil { |
| 550 | return nil, err |
| 551 | } |
| 552 | return &TableSchemaClause{ |
| 553 | SchemaPos: pos, |
| 554 | SchemaEnd: dotIdent.End(), |
| 555 | AliasTable: &TableIdentifier{ |
| 556 | Database: ident, |
| 557 | Table: dotIdent, |
| 558 | }, |
| 559 | }, nil |
| 560 | case p.matchTokenKind(TokenKindLParen): |
| 561 | // it's a table function |
| 562 | argsExpr, err := p.parseTableArgList(pos) |
| 563 | if err != nil { |
| 564 | return nil, err |
| 565 | } |
| 566 | return &TableSchemaClause{ |
| 567 | SchemaPos: pos, |
| 568 | SchemaEnd: p.End(), |
| 569 | TableFunction: &TableFunctionExpr{ |
| 570 | Name: ident, |
no test coverage detected