ast.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. package parser
  2. import (
  3. "github.com/danfragoso/pizzasql-next/pkg/lexer"
  4. "github.com/danfragoso/pizzasql-next/pkg/pgerror"
  5. )
  6. // Node is the base interface for all AST nodes.
  7. type Node interface {
  8. node()
  9. }
  10. // Statement represents a SQL statement.
  11. type Statement interface {
  12. Node
  13. stmtNode()
  14. }
  15. // Expr represents an expression.
  16. type Expr interface {
  17. Node
  18. exprNode()
  19. }
  20. // SetOpType represents a set operation type.
  21. type SetOpType int
  22. const (
  23. SetOpUnion SetOpType = iota
  24. SetOpUnionAll
  25. SetOpIntersect
  26. SetOpExcept
  27. )
  28. // CompoundSelect chains two SELECT statements with a set operation.
  29. type CompoundSelect struct {
  30. Left *SelectStmt
  31. Op SetOpType
  32. Right *SelectStmt // may itself have Compound set for chained ops
  33. OrderBy []OrderByItem
  34. Limit Expr
  35. Offset Expr
  36. }
  37. func (c *CompoundSelect) node() {}
  38. func (c *CompoundSelect) stmtNode() {}
  39. // LockStrength is the row-lock mode of a SELECT locking clause.
  40. type LockStrength int
  41. const (
  42. LockUpdate LockStrength = iota
  43. LockShare
  44. )
  45. // LockWait is the contention policy of a SELECT locking clause.
  46. type LockWait int
  47. const (
  48. LockWaitBlock LockWait = iota
  49. LockWaitNoWait
  50. LockWaitSkipLocked
  51. )
  52. // LockingClause is the trailing FOR UPDATE/SHARE clause of a SELECT.
  53. type LockingClause struct {
  54. Strength LockStrength
  55. Wait LockWait
  56. }
  57. // SelectStmt represents a SELECT statement.
  58. type SelectStmt struct {
  59. Distinct bool
  60. Columns []SelectColumn
  61. From []TableRef
  62. Where Expr
  63. GroupBy []Expr
  64. Having Expr
  65. OrderBy []OrderByItem
  66. Limit Expr
  67. Offset Expr
  68. // Compound chains a set operation onto this SELECT (UNION/INTERSECT/EXCEPT).
  69. Compound *CompoundSelect
  70. // With holds common table expressions that must be materialized before this
  71. // SELECT runs. Non-recursive CTEs are desugared by the parser instead; this
  72. // list carries recursive CTEs (and the CTEs that depend on them).
  73. With []*CTE
  74. // Locking is the trailing row-locking clause, or nil.
  75. Locking *LockingClause
  76. }
  77. // CTE is a common table expression from a WITH clause.
  78. type CTE struct {
  79. Name string
  80. Columns []string
  81. Recursive bool
  82. Query *SelectStmt
  83. }
  84. func (s *SelectStmt) node() {}
  85. func (s *SelectStmt) stmtNode() {}
  86. // SelectColumn represents a column in SELECT.
  87. type SelectColumn struct {
  88. Expr Expr
  89. Alias string
  90. Star bool // true if this is *
  91. TableStar string // table name/alias if this is a qualified wildcard (table.*)
  92. }
  93. // TableRef represents a table reference.
  94. type TableRef struct {
  95. Schema string
  96. Name string
  97. Alias string
  98. Subquery *SelectStmt // for derived tables (SELECT ... FROM (SELECT ...) AS alias)
  99. Join *JoinClause // for joined tables
  100. // Function is set for a table function in FROM (currently only unnest() and
  101. // the jsonb set-returning functions). Name holds the function name so
  102. // ordinary table dispatch ignores it.
  103. Function *FunctionCall
  104. // ColumnAliases holds the optional `AS alias(col, ...)` list that renames a
  105. // table function's output columns.
  106. ColumnAliases []string
  107. }
  108. // ApplyColumnAliases renames a table function's output columns with the
  109. // reference's `AS alias(col, ...)` list. A list whose length does not match the
  110. // function's output arity is rejected, as PostgreSQL does.
  111. func (t *TableRef) ApplyColumnAliases(columns []string) ([]string, error) {
  112. if len(t.ColumnAliases) == 0 {
  113. return columns, nil
  114. }
  115. if len(t.ColumnAliases) != len(columns) {
  116. name := t.Alias
  117. if name == "" {
  118. name = t.Name
  119. }
  120. return nil, pgerror.InvalidColumnReference(
  121. "table %q has %d columns available but %d columns specified",
  122. name, len(columns), len(t.ColumnAliases))
  123. }
  124. return append([]string(nil), t.ColumnAliases...), nil
  125. }
  126. // JoinClause represents a JOIN clause.
  127. type JoinClause struct {
  128. Type JoinType
  129. Table *TableRef
  130. Condition Expr // ON condition
  131. Using []string // USING columns
  132. }
  133. // JoinType represents the type of JOIN.
  134. type JoinType int
  135. const (
  136. JoinInner JoinType = iota
  137. JoinLeft
  138. JoinRight
  139. JoinFull
  140. JoinCross
  141. )
  142. // NullsOrder selects where NULLs sort in an ORDER BY item.
  143. type NullsOrder int
  144. const (
  145. NullsDefault NullsOrder = iota // SQLite default: NULLs are smallest
  146. NullsFirst
  147. NullsLast
  148. )
  149. // OrderByItem represents an ORDER BY item.
  150. type OrderByItem struct {
  151. Expr Expr
  152. Desc bool
  153. NullsOrder NullsOrder
  154. }
  155. // ConflictAction represents the action to take on conflict.
  156. type ConflictAction int
  157. const (
  158. ConflictAbort ConflictAction = iota // Default
  159. ConflictReplace // INSERT OR REPLACE
  160. ConflictIgnore // INSERT OR IGNORE
  161. ConflictFail // INSERT OR FAIL
  162. ConflictRollback // INSERT OR ROLLBACK
  163. )
  164. // InsertStmt represents an INSERT statement.
  165. type InsertStmt struct {
  166. Table *TableRef
  167. Columns []string
  168. Values [][]Expr
  169. // DefaultValues is true for SQLite's INSERT ... DEFAULT VALUES, which
  170. // supplies no values. Values then holds one empty row so the executor
  171. // follows the normal single-row insert path.
  172. DefaultValues bool
  173. Select *SelectStmt // INSERT ... SELECT
  174. OnConflict ConflictAction // OR REPLACE/IGNORE/etc.
  175. ConflictTarget []string
  176. ConflictUpdate []Assignment
  177. ConflictDoNothing bool
  178. Returning []SelectColumn
  179. }
  180. func (s *InsertStmt) node() {}
  181. func (s *InsertStmt) stmtNode() {}
  182. // UpdateStmt represents an UPDATE statement.
  183. type UpdateStmt struct {
  184. Table *TableRef
  185. Set []Assignment
  186. From []TableRef
  187. Where Expr
  188. Returning []SelectColumn
  189. }
  190. func (s *UpdateStmt) node() {}
  191. func (s *UpdateStmt) stmtNode() {}
  192. // Assignment represents a SET assignment.
  193. type Assignment struct {
  194. Column string
  195. Value Expr
  196. }
  197. // DeleteStmt represents a DELETE statement.
  198. type DeleteStmt struct {
  199. Table *TableRef
  200. Where Expr
  201. Returning []SelectColumn
  202. }
  203. func (s *DeleteStmt) node() {}
  204. func (s *DeleteStmt) stmtNode() {}
  205. // CreateTableStmt represents a CREATE TABLE statement.
  206. type CreateTableStmt struct {
  207. IfNotExists bool
  208. Table *TableRef
  209. Columns []ColumnDef
  210. Constraints []TableConstraint
  211. }
  212. func (s *CreateTableStmt) node() {}
  213. func (s *CreateTableStmt) stmtNode() {}
  214. // ColumnDef represents a column definition.
  215. type ColumnDef struct {
  216. Name string
  217. Type DataType
  218. Constraints []ColumnConstraint
  219. // GeneratedExpr is non-nil for a GENERATED ALWAYS AS (expr) column. A
  220. // generated column's value is computed rather than supplied by the user.
  221. GeneratedExpr Expr
  222. GeneratedStored bool // true for STORED, false for VIRTUAL
  223. }
  224. // DataType represents a SQL data type.
  225. type DataType struct {
  226. Name string
  227. Precision int // for VARCHAR(n), NUMERIC(p,s)
  228. Scale int // for NUMERIC(p,s)
  229. Array bool // trailing [] declares a one-dimensional array
  230. }
  231. // SQLTypeName returns the type name as it is persisted in the catalog: the
  232. // base name plus a [] suffix for arrays. Precision and scale are not part of
  233. // the catalog shape because the engine does not enforce them.
  234. func (d DataType) SQLTypeName() string {
  235. if d.Array {
  236. return d.Name + "[]"
  237. }
  238. return d.Name
  239. }
  240. // ColumnConstraint represents a column-level constraint.
  241. type ColumnConstraint struct {
  242. Type ConstraintType
  243. Name string // optional constraint name
  244. Default Expr // for DEFAULT
  245. RefTable string // for REFERENCES
  246. RefColumns []string // for REFERENCES (empty means the parent's primary key)
  247. Check Expr // for CHECK
  248. // OnDelete and OnUpdate record the foreign-key referential actions. The
  249. // engine enforces foreign keys immediately and implements no cascades, so
  250. // only NO ACTION and RESTRICT are accepted; the rest are rejected at DDL.
  251. OnDelete ReferentialAction
  252. OnUpdate ReferentialAction
  253. // Deferrable is set for a DEFERRABLE clause. Deferred enforcement is not
  254. // implemented, so DDL rejects it instead of accepting a weaker guarantee.
  255. Deferrable bool
  256. // OnConflict is the conflict resolution algorithm declared with
  257. // ON CONFLICT REPLACE/etc. (ConflictAbort is the zero value/default).
  258. OnConflict ConflictAction
  259. HasOnConflict bool
  260. }
  261. // ConstraintType represents the type of constraint.
  262. type ConstraintType int
  263. const (
  264. ConstraintPrimaryKey ConstraintType = iota
  265. ConstraintNotNull
  266. ConstraintUnique
  267. ConstraintDefault
  268. ConstraintCheck
  269. ConstraintForeignKey
  270. ConstraintAutoIncrement
  271. )
  272. // ReferentialAction is a parsed foreign-key ON DELETE/ON UPDATE action.
  273. type ReferentialAction int
  274. const (
  275. // RefActionUnspecified is the default (no clause, equivalent to NO ACTION).
  276. RefActionUnspecified ReferentialAction = iota
  277. RefActionNoAction
  278. RefActionRestrict
  279. RefActionCascade
  280. RefActionSetNull
  281. RefActionSetDefault
  282. )
  283. // String returns the SQL spelling of the action.
  284. func (a ReferentialAction) String() string {
  285. switch a {
  286. case RefActionNoAction:
  287. return "NO ACTION"
  288. case RefActionRestrict:
  289. return "RESTRICT"
  290. case RefActionCascade:
  291. return "CASCADE"
  292. case RefActionSetNull:
  293. return "SET NULL"
  294. case RefActionSetDefault:
  295. return "SET DEFAULT"
  296. default:
  297. return ""
  298. }
  299. }
  300. // TableConstraint represents a table-level constraint.
  301. type TableConstraint struct {
  302. Type ConstraintType
  303. Name string // optional constraint name
  304. Columns []string // columns involved
  305. RefTable string // for FOREIGN KEY
  306. RefColumns []string // for FOREIGN KEY
  307. Check Expr // for CHECK
  308. // OnDelete and OnUpdate record the foreign-key referential actions.
  309. OnDelete ReferentialAction
  310. OnUpdate ReferentialAction
  311. // Deferrable is set for a DEFERRABLE clause.
  312. Deferrable bool
  313. // OnConflict is the conflict resolution declared with ON CONFLICT
  314. // REPLACE/etc.; HasOnConflict distinguishes it from the default ABORT.
  315. OnConflict ConflictAction
  316. HasOnConflict bool
  317. }
  318. // DropTableStmt represents a DROP TABLE statement.
  319. type DropTableStmt struct {
  320. IfExists bool
  321. Tables []*TableRef
  322. }
  323. func (s *DropTableStmt) node() {}
  324. func (s *DropTableStmt) stmtNode() {}
  325. // CreateIndexStmt represents a CREATE INDEX statement.
  326. type CreateIndexStmt struct {
  327. IfNotExists bool
  328. Unique bool
  329. Name string
  330. Table string
  331. Columns []IndexColumn
  332. }
  333. func (s *CreateIndexStmt) node() {}
  334. func (s *CreateIndexStmt) stmtNode() {}
  335. // IndexColumn represents a column in an index. Expr is set for expression
  336. // indexes (e.g. an index on lower(email)); a plain column index leaves it nil
  337. // and uses Name.
  338. type IndexColumn struct {
  339. Name string
  340. Desc bool // true for DESC ordering
  341. Expr Expr
  342. }
  343. // DropIndexStmt represents a DROP INDEX statement.
  344. type DropIndexStmt struct {
  345. IfExists bool
  346. Name string
  347. }
  348. func (s *DropIndexStmt) node() {}
  349. func (s *DropIndexStmt) stmtNode() {}
  350. // CreateViewStmt represents a CREATE VIEW statement.
  351. type CreateViewStmt struct {
  352. IfNotExists bool
  353. View *TableRef
  354. Select *SelectStmt
  355. }
  356. func (s *CreateViewStmt) node() {}
  357. func (s *CreateViewStmt) stmtNode() {}
  358. // DropViewStmt represents a DROP VIEW statement.
  359. type DropViewStmt struct {
  360. IfExists bool
  361. Views []*TableRef
  362. }
  363. func (s *DropViewStmt) node() {}
  364. func (s *DropViewStmt) stmtNode() {}
  365. // AlterTableStmt represents an ALTER TABLE statement.
  366. type AlterTableStmt struct {
  367. Table string
  368. Action AlterAction
  369. }
  370. func (s *AlterTableStmt) node() {}
  371. func (s *AlterTableStmt) stmtNode() {}
  372. // AlterAction represents an ALTER TABLE action.
  373. type AlterAction interface {
  374. Node
  375. alterAction()
  376. }
  377. // AddColumnAction represents ADD COLUMN action.
  378. type AddColumnAction struct {
  379. Column *ColumnDef
  380. IfNotExists bool
  381. }
  382. func (a *AddColumnAction) node() {}
  383. func (a *AddColumnAction) alterAction() {}
  384. // DropColumnAction represents DROP COLUMN action.
  385. type DropColumnAction struct {
  386. Column string
  387. }
  388. func (a *DropColumnAction) node() {}
  389. func (a *DropColumnAction) alterAction() {}
  390. // RenameTableAction represents RENAME TO action.
  391. type RenameTableAction struct {
  392. NewName string
  393. }
  394. func (a *RenameTableAction) node() {}
  395. func (a *RenameTableAction) alterAction() {}
  396. // RenameColumnAction represents RENAME COLUMN action.
  397. type RenameColumnAction struct {
  398. OldName string
  399. NewName string
  400. }
  401. func (a *RenameColumnAction) node() {}
  402. func (a *RenameColumnAction) alterAction() {}
  403. // AttachStmt represents an ATTACH DATABASE statement.
  404. type AttachStmt struct {
  405. FilePath string // Database file path or identifier
  406. Alias string // Database alias name
  407. }
  408. func (s *AttachStmt) node() {}
  409. func (s *AttachStmt) stmtNode() {}
  410. // DetachStmt represents a DETACH DATABASE statement.
  411. type DetachStmt struct {
  412. Alias string // Database alias to detach
  413. }
  414. func (s *DetachStmt) node() {}
  415. func (s *DetachStmt) stmtNode() {}
  416. // PragmaStmt represents a PRAGMA statement.
  417. type PragmaStmt struct {
  418. Name string // pragma name (e.g., "table_info")
  419. Arg string // optional argument (e.g., table name)
  420. Value Expr // optional value for SET pragmas
  421. }
  422. func (s *PragmaStmt) node() {}
  423. func (s *PragmaStmt) stmtNode() {}
  424. // AnalyzeStmt represents an ANALYZE statement. PizzaSQL does not maintain
  425. // optimizer statistics, so it is accepted and executed as a documented no-op.
  426. type AnalyzeStmt struct {
  427. Name string // optional table name
  428. }
  429. func (s *AnalyzeStmt) node() {}
  430. func (s *AnalyzeStmt) stmtNode() {}
  431. // ExplainStmt represents an EXPLAIN statement.
  432. type ExplainStmt struct {
  433. QueryPlan bool // true for EXPLAIN QUERY PLAN
  434. Statement Statement // the statement being explained
  435. }
  436. func (s *ExplainStmt) node() {}
  437. func (s *ExplainStmt) stmtNode() {}
  438. // Transaction statements
  439. // BeginStmt represents a BEGIN TRANSACTION statement.
  440. type BeginStmt struct {
  441. // Transaction mode (DEFERRED, IMMEDIATE, EXCLUSIVE) - for future use
  442. Mode string
  443. }
  444. func (s *BeginStmt) node() {}
  445. func (s *BeginStmt) stmtNode() {}
  446. // CommitStmt represents a COMMIT statement.
  447. type CommitStmt struct{}
  448. func (s *CommitStmt) node() {}
  449. func (s *CommitStmt) stmtNode() {}
  450. // RollbackStmt represents a ROLLBACK statement.
  451. type RollbackStmt struct {
  452. Savepoint string // for ROLLBACK TO SAVEPOINT
  453. }
  454. func (s *RollbackStmt) node() {}
  455. func (s *RollbackStmt) stmtNode() {}
  456. // SavepointStmt represents a SAVEPOINT statement.
  457. type SavepointStmt struct {
  458. Name string
  459. }
  460. func (s *SavepointStmt) node() {}
  461. func (s *SavepointStmt) stmtNode() {}
  462. // ReleaseStmt represents a RELEASE SAVEPOINT statement.
  463. type ReleaseStmt struct {
  464. Name string
  465. }
  466. func (s *ReleaseStmt) node() {}
  467. func (s *ReleaseStmt) stmtNode() {}
  468. // Notification statements
  469. // ListenStmt represents LISTEN channel.
  470. type ListenStmt struct {
  471. Channel string
  472. }
  473. func (s *ListenStmt) node() {}
  474. func (s *ListenStmt) stmtNode() {}
  475. // UnlistenStmt represents UNLISTEN channel or UNLISTEN *.
  476. type UnlistenStmt struct {
  477. Channel string
  478. All bool
  479. }
  480. func (s *UnlistenStmt) node() {}
  481. func (s *UnlistenStmt) stmtNode() {}
  482. // NotifyStmt represents NOTIFY channel [, payload].
  483. type NotifyStmt struct {
  484. Channel string
  485. Payload string
  486. }
  487. func (s *NotifyStmt) node() {}
  488. func (s *NotifyStmt) stmtNode() {}
  489. // SetStmt represents a PostgreSQL SET statement. Drivers and ORMs issue these
  490. // for session configuration; PizzaSQL accepts them for compatibility and only
  491. // gives search_path observable behavior. Name is the normalized setting name
  492. // (for example "search_path" or "time zone") and Values holds the unquoted
  493. // value tokens in declaration order.
  494. type SetStmt struct {
  495. Name string
  496. Values []string
  497. Local bool
  498. }
  499. func (s *SetStmt) node() {}
  500. func (s *SetStmt) stmtNode() {}
  501. // ShowStmt represents a PostgreSQL SHOW statement for a single setting.
  502. type ShowStmt struct {
  503. Name string
  504. }
  505. func (s *ShowStmt) node() {}
  506. func (s *ShowStmt) stmtNode() {}
  507. // Expression types
  508. // BinaryExpr represents a binary expression.
  509. type BinaryExpr struct {
  510. Left Expr
  511. Op lexer.TokenType
  512. Right Expr
  513. }
  514. func (e *BinaryExpr) node() {}
  515. func (e *BinaryExpr) exprNode() {}
  516. // UnaryExpr represents a unary expression.
  517. type UnaryExpr struct {
  518. Op lexer.TokenType
  519. Operand Expr
  520. }
  521. func (e *UnaryExpr) node() {}
  522. func (e *UnaryExpr) exprNode() {}
  523. // LiteralExpr represents a literal value.
  524. type LiteralExpr struct {
  525. Type lexer.TokenType // TokenNumber, TokenString, TokenNULL, TokenTRUE, TokenFALSE
  526. Value string
  527. }
  528. func (e *LiteralExpr) node() {}
  529. func (e *LiteralExpr) exprNode() {}
  530. // ColumnRef represents a column reference.
  531. type ColumnRef struct {
  532. Table string
  533. Column string
  534. }
  535. func (e *ColumnRef) node() {}
  536. func (e *ColumnRef) exprNode() {}
  537. // FunctionCall represents a function call.
  538. type FunctionCall struct {
  539. Name string
  540. Args []Expr
  541. Distinct bool // for COUNT(DISTINCT x)
  542. Star bool // for COUNT(*)
  543. }
  544. func (e *FunctionCall) node() {}
  545. func (e *FunctionCall) exprNode() {}
  546. // WindowExpr represents a function call with an OVER clause.
  547. type WindowExpr struct {
  548. Func *FunctionCall
  549. PartitionBy []Expr
  550. OrderBy []OrderByItem
  551. }
  552. func (e *WindowExpr) node() {}
  553. func (e *WindowExpr) exprNode() {}
  554. // SubqueryExpr represents a subquery expression.
  555. type SubqueryExpr struct {
  556. Query *SelectStmt
  557. }
  558. func (e *SubqueryExpr) node() {}
  559. func (e *SubqueryExpr) exprNode() {}
  560. // CaseExpr represents a CASE expression.
  561. type CaseExpr struct {
  562. Operand Expr // for CASE operand WHEN...
  563. Whens []WhenClause
  564. Else Expr
  565. }
  566. func (e *CaseExpr) node() {}
  567. func (e *CaseExpr) exprNode() {}
  568. // WhenClause represents a WHEN clause in CASE.
  569. type WhenClause struct {
  570. Condition Expr
  571. Result Expr
  572. }
  573. // InExpr represents an IN expression.
  574. type InExpr struct {
  575. Left Expr
  576. Not bool
  577. Values []Expr // IN (1, 2, 3)
  578. Subquery *SelectStmt // IN (SELECT ...)
  579. }
  580. func (e *InExpr) node() {}
  581. func (e *InExpr) exprNode() {}
  582. // BetweenExpr represents a BETWEEN expression.
  583. type BetweenExpr struct {
  584. Left Expr
  585. Not bool
  586. Low Expr
  587. High Expr
  588. }
  589. func (e *BetweenExpr) node() {}
  590. func (e *BetweenExpr) exprNode() {}
  591. // LikeExpr represents a LIKE expression.
  592. type LikeExpr struct {
  593. Left Expr
  594. Not bool
  595. Pattern Expr
  596. Escape Expr
  597. }
  598. func (e *LikeExpr) node() {}
  599. func (e *LikeExpr) exprNode() {}
  600. // IsNullExpr represents an IS NULL expression.
  601. type IsNullExpr struct {
  602. Left Expr
  603. Not bool
  604. }
  605. func (e *IsNullExpr) node() {}
  606. func (e *IsNullExpr) exprNode() {}
  607. // IsDistinctExpr represents `left IS DISTINCT FROM right` (Not=false) or
  608. // `left IS NOT DISTINCT FROM right` (Not=true). Unlike `=`, NULLs compare
  609. // equal to each other and distinct from non-NULLs.
  610. type IsDistinctExpr struct {
  611. Left Expr
  612. Right Expr
  613. Not bool
  614. }
  615. func (e *IsDistinctExpr) node() {}
  616. func (e *IsDistinctExpr) exprNode() {}
  617. // CastExpr represents a CAST expression.
  618. type CastExpr struct {
  619. Expr Expr
  620. Type DataType
  621. }
  622. func (e *CastExpr) node() {}
  623. func (e *CastExpr) exprNode() {}
  624. // ExistsExpr represents an EXISTS expression.
  625. type ExistsExpr struct {
  626. Subquery *SelectStmt
  627. }
  628. func (e *ExistsExpr) node() {}
  629. func (e *ExistsExpr) exprNode() {}
  630. // ArrayExpr represents the ARRAY[...] constructor. Elements are evaluated as
  631. // ordinary expressions; NULL elements survive as NULL array elements.
  632. type ArrayExpr struct {
  633. Elements []Expr
  634. }
  635. func (e *ArrayExpr) node() {}
  636. func (e *ArrayExpr) exprNode() {}
  637. // SubscriptExpr represents a 1-based array element access, arr[index].
  638. type SubscriptExpr struct {
  639. Expr Expr
  640. Index Expr
  641. }
  642. func (e *SubscriptExpr) node() {}
  643. func (e *SubscriptExpr) exprNode() {}
  644. // AnyAllExpr represents `left op ANY(array)` (All=false) or
  645. // `left op ALL(array)` (All=true). It evaluates with SQL three-valued logic.
  646. type AnyAllExpr struct {
  647. Left Expr
  648. Op lexer.TokenType
  649. All bool
  650. Array Expr
  651. }
  652. func (e *AnyAllExpr) node() {}
  653. func (e *AnyAllExpr) exprNode() {}
  654. // ParenExpr represents a parenthesized expression.
  655. type ParenExpr struct {
  656. Expr Expr
  657. }
  658. func (e *ParenExpr) node() {}
  659. func (e *ParenExpr) exprNode() {}