Skip to content

Commit dc92da8

Browse files
committed
Add ScalarSubquery and BooleanIsNullExpression support
- Add ScalarSubquery for (SELECT ...) in expressions - Add BooleanIsNullExpression for IS NULL/IS NOT NULL predicates - Add IS keyword to lexer
1 parent a4ea5be commit dc92da8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ast/scalar_subquery.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ast
2+
3+
// ScalarSubquery represents a scalar subquery expression.
4+
type ScalarSubquery struct {
5+
QueryExpression QueryExpression
6+
}
7+
8+
func (s *ScalarSubquery) node() {}
9+
func (s *ScalarSubquery) scalarExpression() {}

parser/parser.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,20 @@ func (p *Parser) parsePrimaryExpression() (ast.ScalarExpression, error) {
880880
case TokenLBrace:
881881
return p.parseOdbcLiteral()
882882
case TokenLParen:
883-
// Parenthesized expression or subquery
883+
// Parenthesized expression or scalar subquery
884884
p.nextToken()
885+
// Check if it's a scalar subquery (starts with SELECT)
886+
if p.curTok.Type == TokenSelect {
887+
qe, err := p.parseQueryExpression()
888+
if err != nil {
889+
return nil, err
890+
}
891+
if p.curTok.Type != TokenRParen {
892+
return nil, fmt.Errorf("expected ), got %s", p.curTok.Literal)
893+
}
894+
p.nextToken()
895+
return &ast.ScalarSubquery{QueryExpression: qe}, nil
896+
}
885897
expr, err := p.parseScalarExpression()
886898
if err != nil {
887899
return nil, err
@@ -4369,6 +4381,14 @@ func scalarExpressionToJSON(expr ast.ScalarExpression) jsonNode {
43694381
node["Expression"] = scalarExpressionToJSON(e.Expression)
43704382
}
43714383
return node
4384+
case *ast.ScalarSubquery:
4385+
node := jsonNode{
4386+
"$type": "ScalarSubquery",
4387+
}
4388+
if e.QueryExpression != nil {
4389+
node["QueryExpression"] = queryExpressionToJSON(e.QueryExpression)
4390+
}
4391+
return node
43724392
default:
43734393
return jsonNode{"$type": "UnknownScalarExpression"}
43744394
}

0 commit comments

Comments
 (0)