parser

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package parser implements a parser for ClickHouse SQL.

Index

Constants

View Source
const (
	LOWEST       = iota
	ALIAS_PREC   // AS
	TERNARY_PREC // ? : (ternary operator - very low precedence in ClickHouse)
	OR_PREC      // OR
	AND_PREC     // AND
	NOT_PREC     // NOT
	COMPARE      // =, !=, <, >, <=, >=, LIKE, IN, BETWEEN, IS
	CONCAT_PREC  // ||
	ADD_PREC     // +, -
	MUL_PREC     // *, /, %
	UNARY        // -x, NOT x
	CALL         // function(), array[]
	HIGHEST
)

Operator precedence levels

Variables

This section is empty.

Functions

func Explain

func Explain(stmt ast.Statement) string

Explain returns the EXPLAIN AST output for a statement, matching ClickHouse's format.

func ExplainStatements

func ExplainStatements(stmts []ast.Statement) string

ExplainStatements returns the EXPLAIN AST output for multiple statements. This handles the special ClickHouse behavior where INSERT VALUES followed by SELECT on the same line outputs the INSERT AST and then executes the SELECT, printing its result.

func Parse

func Parse(ctx context.Context, r io.Reader) ([]ast.Statement, error)

Parse parses SQL statements from the input.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses ClickHouse SQL statements.

func New

func New(r io.Reader) *Parser

New creates a new Parser from an io.Reader.

func (*Parser) ParseStatements

func (p *Parser) ParseStatements(ctx context.Context) ([]ast.Statement, error)

ParseStatements parses multiple SQL statements.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL