Struct sql_parser::parser::Parser[][src]

struct Parser<'a> {
    sql: &'a str,
    tokens: Vec<(Token, usize)>,
    index: usize,
    recursion_guard: RecursionGuard,
}
Expand description

SQL Parser

Fields

sql: &'a strtokens: Vec<(Token, usize)>index: usize

The index of the first unprocessed token in self.tokens

recursion_guard: RecursionGuard

Implementations

Parse the specified tokens

Parse a single top-level statement (such as SELECT, INSERT, CREATE, etc.), stopping before the statement separator, if any.

Parse a new expression

Parse tokens until the precedence changes

Parse an expression prefix

Parses an expression that appears in parentheses, like (1 + 1) or (SELECT 1). Assumes that the opening parenthesis has already been parsed. Parses up to the closing parenthesis without consuming it.

Parse CURRENT ROW or { <positive number> | UNBOUNDED } { PRECEDING | FOLLOWING }

Parse a SQL CAST function e.g. CAST(expr AS FLOAT)

Parse a SQL EXISTS expression e.g. WHERE EXISTS(SELECT ...).

Parse an INTERVAL literal.

Some syntactically valid intervals:

  1. INTERVAL '1' DAY
  2. INTERVAL '1-1' YEAR TO MONTH
  3. INTERVAL '1' SECOND
  4. `INTERVAL ‘1:1’ MINUTE TO SECOND
  5. INTERVAL '1:1:1.1' HOUR TO SECOND (5)
  6. INTERVAL '1.111' SECOND (2)

Parse an operator following an expression

Parse subscript expression, i.e. either an index value or slice range.

Parse a possibly qualified, possibly quoted operator, e.g. +, pg_catalog.+, or "pg_catalog".+

Parses the parens following the [ NOT ] IN operator

Parses BETWEEN <low> AND <high>, assuming the BETWEEN keyword was already consumed

Parse a postgresql casting style which is in the form of expr::datatype

Get the precedence of the next token

Return the first non-whitespace token that has not yet been processed (or None if reached end-of-file)

Return the nth token that has not yet been processed.

Return the next token that has not yet been processed, or None if reached end-of-file, and mark it as processed. OK to call repeatedly after reaching EOF.

Push back the last one non-whitespace token. Must be called after next_token(), otherwise might panic. OK to call after next_token() indicates an EOF.

Return the byte position within the query string at which the next token starts.

Return the byte position within the query string at which the previous token starts.

Must be called after next_token(), otherwise might panic. OK to call after next_token() indicates an EOF.

Report unexpected token

Look for an expected keyword and consume it if it exists

Look for an expected sequence of keywords and consume them if they exist

Look for one of the given keywords and return the one that matches.

Bail out if the current token is not one of the expected keywords, or consume it if it is

Bail out if the current token is not an expected keyword, or consume it if it is

Bail out if the following tokens are not the expected sequence of keywords, or consume them if they are.

Consume the next token if it matches the expected token, otherwise return false

Bail out if the current token is not an expected keyword, or consume it if it is

Parse a comma-separated list of 1+ items accepted by F

Parse a SQL CREATE statement

Parses the column section of a CREATE SOURCE statement which can be empty or a comma-separated list of column identifiers and a single key constraint, e.g.

(col_0, col_i, …, col_n, key_constraint)

Parses a key constraint.

If require_equals is true, parse options of the form KEY = VALUE or just KEY. If require_equals is false, additionally support KEY VALUE (but still the others).

Parse a copy statement

Parse a literal value (numbers, strings, date/time, booleans)

Parse an unsigned literal integer/long

Parse a literal string

Parse a SQL datatype (in the context of a CREATE TABLE statement for example)

Parse AS identifier (or simply identifier if it’s not a reserved keyword) Some examples with aliases: SELECT 1 foo, SELECT COUNT(*) AS cnt, SELECT ... FROM t1 foo, t2 bar, SELECT ... FROM (...) AS bar

Parse AS identifier when the AS is describing a table-valued object, like in ... FROM generate_series(1, 10) AS t (col). In this case the alias is allowed to optionally name the columns in the table, in addition to the table itself.

Parse a possibly qualified, possibly quoted identifier, e.g. foo or myschema."table"

Parse a simple one-word identifier (possibly quoted, possibly a keyword)

Parse a parenthesized comma-separated list of unqualified, possibly quoted identifiers

Parse a query expression, i.e. a SELECT statement optionally preceeded with some WITH CTE declarations and optionally followed by ORDER BY. Unlike some other parse_… methods, this one doesn’t expect the initial keyword to be already consumed

Parse a CTE (alias [( col1, col2, ... )] AS (subquery))

Parse a “query body”, which is an expression with roughly the following grammar:

  query_body ::= restricted_select | '(' subquery ')' | set_operation
  restricted_select ::= 'SELECT' [expr_list] [ from ] [ where ] [ groupby_having ]
  subquery ::= query_body [ order_by_limit ]
  set_operation ::= query_body { 'UNION' | 'EXCEPT' | 'INTERSECT' } [ 'ALL' ] query_body

Parse a restricted SELECT statement (no CTEs / UNION / ORDER BY), assuming the initial SELECT was already consumed

A table name or a parenthesized subquery, followed by optional [AS] alias

Parse an INSERT statement

Parse a var = expr assignment, used in an UPDATE statement

Parse AS OF, if present.

Parse a comma-delimited list of projections after SELECT

Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)

Parse an EXPLAIN statement, assuming that the EXPLAIN token has already been consumed.

Parse a DECLARE statement, assuming that the DECLARE token has already been consumed.

Parse a CLOSE statement, assuming that the CLOSE token has already been consumed.

Parse a PREPARE statement, assuming that the PREPARE token has already been consumed.

Parse a EXECUTE statement, assuming that the EXECUTE token has already been consumed.

Parse a DEALLOCATE statement, assuming that the DEALLOCATE token has already been consumed.

Parse a FETCH statement, assuming that the FETCH token has already been consumed.

Trait Implementations

Extracts a reference to the recursion guard embedded within the type.

Checks whether it is safe to recur and calls f if so. Read more

Like CheckedRecursion::checked_recur, but operates on a mutable reference to Self. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more