Skip to content

Commit d818580

Browse files
authored
Support DESCRIBE TABLE syntax (#183)
1 parent 2590403 commit d818580

16 files changed

+73
-4
lines changed

parser/ast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8338,6 +8338,7 @@ func (s *ShowStmt) Accept(visitor ASTVisitor) error {
83388338
type DescribeStmt struct {
83398339
DescribePos Pos
83408340
StatementEnd Pos
8341+
DescribeType string // e.g., "TABLE", empty if not used
83418342
Target *TableIdentifier
83428343
}
83438344

@@ -8352,6 +8353,10 @@ func (d *DescribeStmt) End() Pos {
83528353
func (d *DescribeStmt) String() string {
83538354
var builder strings.Builder
83548355
builder.WriteString("DESCRIBE ")
8356+
if d.DescribeType != "" {
8357+
builder.WriteString(d.DescribeType)
8358+
builder.WriteString(" ")
8359+
}
83558360
builder.WriteString(d.Target.String())
83568361
return builder.String()
83578362
}

parser/parser_table.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,13 @@ func (p *Parser) parseDescribeStmt(pos Pos) (*DescribeStmt, error) {
13081308
}
13091309
_ = p.lexer.consumeToken()
13101310

1311+
// TABLE keyword is optional after DESC/DESCRIBE
1312+
var describeType string
1313+
if p.matchKeyword(KeywordTable) {
1314+
_ = p.lexer.consumeToken()
1315+
describeType = "TABLE"
1316+
}
1317+
13111318
tableIdent, err := p.parseTableIdentifier(p.Pos())
13121319
if err != nil {
13131320
return nil, err
@@ -1316,6 +1323,7 @@ func (p *Parser) parseDescribeStmt(pos Pos) (*DescribeStmt, error) {
13161323
return &DescribeStmt{
13171324
DescribePos: pos,
13181325
StatementEnd: tableIdent.End(),
1326+
DescribeType: describeType,
13191327
Target: tableIdent,
13201328
}, nil
13211329
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DESC TABLE mytable
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DESCRIBE TABLE mytable
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Origin SQL:
2-
DESC mytable
2+
DESC TABLE mytable
33

44
-- Format SQL:
5-
DESCRIBE mytable;
5+
DESCRIBE TABLE mytable;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Origin SQL:
2+
DESC TABLE mytable
3+
4+
-- Format SQL:
5+
DESCRIBE TABLE mytable;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Origin SQL:
2+
DESC mytable
3+
4+
-- Format SQL:
5+
DESCRIBE mytable;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Origin SQL:
2-
DESCRIBE mytable
2+
DESCRIBE TABLE mytable
33

44
-- Format SQL:
5-
DESCRIBE mytable;
5+
DESCRIBE TABLE mytable;

0 commit comments

Comments
 (0)