Struct sqlparser::parser::Parser

source ·
pub struct Parser<'a> { /* private fields */ }

Implementations§

source§

impl<'a> Parser<'a>

source§

impl<'a> Parser<'a>

source

pub fn new(dialect: &'a dyn Dialect) -> Self

Create a parser for a Dialect

See also Parser::parse_sql

Example:

let dialect = GenericDialect{};
let statements = Parser::new(&dialect)
  .try_with_sql("SELECT * FROM foo")?
  .parse_statements()?;
source

pub fn with_recursion_limit(self, recursion_limit: usize) -> Self

Specify the maximum recursion limit while parsing.

Parser prevents stack overflows by returning ParserError::RecursionLimitExceeded if the parser exceeds this depth while processing the query.

Example:

let dialect = GenericDialect{};
let result = Parser::new(&dialect)
  .with_recursion_limit(1)
  .try_with_sql("SELECT * FROM foo WHERE (a OR (b OR (c OR d)))")?
  .parse_statements();
  assert_eq!(result, Err(ParserError::RecursionLimitExceeded));
source

pub fn with_options(self, options: ParserOptions) -> Self

Specify additional parser options

Parser supports additional options (ParserOptions) that allow you to mix & match behavior otherwise constrained to certain dialects (e.g. trailing commas).

Example:

let dialect = GenericDialect{};
let options = ParserOptions::new()
   .with_trailing_commas(true)
   .with_unescape(false);
let result = Parser::new(&dialect)
  .with_options(options)
  .try_with_sql("SELECT a, b, COUNT(*), FROM foo GROUP BY a, b,")?
  .parse_statements();
  assert!(matches!(result, Ok(_)));
source

pub fn with_tokens_with_locations(self, tokens: Vec<TokenWithLocation>) -> Self

Reset this parser to parse the specified token stream

source

pub fn with_tokens(self, tokens: Vec<Token>) -> Self

Reset this parser state to parse the specified tokens

source

pub fn try_with_sql(self, sql: &str) -> Result<Self, ParserError>

Tokenize the sql string and sets this Parser’s state to parse the resulting tokens

Returns an error if there was an error tokenizing the SQL string.

See example on Parser::new() for an example

source

pub fn parse_statements(&mut self) -> Result<Vec<Statement>, ParserError>

Parse potentially multiple statements

Example

let dialect = GenericDialect{};
let statements = Parser::new(&dialect)
  // Parse a SQL string with 2 separate statements
  .try_with_sql("SELECT * FROM foo; SELECT * FROM bar;")?
  .parse_statements()?;
assert_eq!(statements.len(), 2);
source

pub fn parse_sql( dialect: &dyn Dialect, sql: &str ) -> Result<Vec<Statement>, ParserError>

Convenience method to parse a string with one or more SQL statements into produce an Abstract Syntax Tree (AST).

Example

let dialect = GenericDialect{};
let statements = Parser::parse_sql(
  &dialect, "SELECT * FROM foo"
)?;
assert_eq!(statements.len(), 1);
source

pub fn parse_statement(&mut self) -> Result<Statement, ParserError>

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

source

pub fn parse_flush(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_msck(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_truncate(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_attach_duckdb_database_options( &mut self ) -> Result<Vec<AttachDuckDBDatabaseOption>, ParserError>

source

pub fn parse_attach_duckdb_database(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_detach_duckdb_database(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_attach_database(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_analyze(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_wildcard_expr(&mut self) -> Result<Expr, ParserError>

Parse a new expression including wildcard & qualified wildcard

source

pub fn parse_expr(&mut self) -> Result<Expr, ParserError>

Parse a new expression

source

pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError>

Parse tokens until the precedence changes

source

pub fn parse_interval_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn get_next_interval_precedence(&self) -> Result<u8, ParserError>

Get the precedence of the next token With AND, OR, and XOR

source

pub fn parse_assert(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_savepoint(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_release(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_prefix(&mut self) -> Result<Expr, ParserError>

Parse an expression prefix

source

pub fn parse_function(&mut self, name: ObjectName) -> Result<Expr, ParserError>

source

pub fn parse_time_functions( &mut self, name: ObjectName ) -> Result<Expr, ParserError>

source

pub fn parse_window_frame_units( &mut self ) -> Result<WindowFrameUnits, ParserError>

source

pub fn parse_window_frame(&mut self) -> Result<WindowFrame, ParserError>

source

pub fn parse_window_frame_bound( &mut self ) -> Result<WindowFrameBound, ParserError>

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

source

pub fn parse_case_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_optional_cast_format( &mut self ) -> Result<Option<CastFormat>, ParserError>

source

pub fn parse_convert_expr(&mut self) -> Result<Expr, ParserError>

Parse a SQL CONVERT function:

  • CONVERT('héhé' USING utf8mb4) (MySQL)
  • CONVERT('héhé', CHAR CHARACTER SET utf8mb4) (MySQL)
  • CONVERT(DECIMAL(10, 5), 42) (MSSQL) - the type comes first
source

pub fn parse_cast_expr(&mut self, kind: CastKind) -> Result<Expr, ParserError>

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

source

pub fn parse_exists_expr(&mut self, negated: bool) -> Result<Expr, ParserError>

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

source

pub fn parse_extract_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_ceil_floor_expr( &mut self, is_ceil: bool ) -> Result<Expr, ParserError>

source

pub fn parse_position_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_substring_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_overlay_expr(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError>

TRIM ([WHERE] ['text' FROM] 'text')
TRIM ('text')
TRIM(<expr>, [, characters]) -- only Snowflake or BigQuery
source

pub fn parse_trim_where(&mut self) -> Result<TrimWhereField, ParserError>

source

pub fn parse_array_expr(&mut self, named: bool) -> Result<Expr, ParserError>

Parses an array expression [ex1, ex2, ..] if named is true, came from an expression like ARRAY[ex1, ex2]

source

pub fn parse_listagg_on_overflow( &mut self ) -> Result<Option<ListAggOnOverflow>, ParserError>

source

pub fn parse_date_time_field(&mut self) -> Result<DateTimeField, ParserError>

source

pub fn parse_not(&mut self) -> Result<Expr, ParserError>

source

pub fn parse_match_against(&mut self) -> Result<Expr, ParserError>

Parses fulltext expressions (1)

§Errors

This method will raise an error if the column list is empty or with invalid identifiers, the match expression is not a literal string, or if the search modifier is not valid.

source

pub fn parse_interval(&mut self) -> Result<Expr, ParserError>

Parse an INTERVAL expression.

Some syntactically valid intervals:

  1. INTERVAL '1' DAY
  2. INTERVAL '1-1' YEAR TO MONTH
  3. INTERVAL '1' SECOND
  4. INTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)
  5. INTERVAL '1.1' SECOND (2, 2)
  6. INTERVAL '1:1' HOUR (5) TO MINUTE (5)
  7. (MySql and BigQuey only):INTERVAL 1 DAY

Note that we do not currently attempt to parse the quoted value.

source

pub fn parse_infix( &mut self, expr: Expr, precedence: u8 ) -> Result<Expr, ParserError>

Parse an operator following an expression

source

pub fn parse_escape_char(&mut self) -> Result<Option<String>, ParserError>

parse the ESCAPE CHAR portion of LIKE, ILIKE, and SIMILAR TO

source

pub fn parse_array_index(&mut self, expr: Expr) -> Result<Expr, ParserError>

source

pub fn parse_map_access(&mut self, expr: Expr) -> Result<Expr, ParserError>

source

pub fn parse_in( &mut self, expr: Expr, negated: bool ) -> Result<Expr, ParserError>

Parses the parens following the [ NOT ] IN operator

source

pub fn parse_between( &mut self, expr: Expr, negated: bool ) -> Result<Expr, ParserError>

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

source

pub fn parse_pg_cast(&mut self, expr: Expr) -> Result<Expr, ParserError>

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

source

pub fn get_next_precedence(&self) -> Result<u8, ParserError>

Get the precedence of the next token

source

pub fn peek_token(&self) -> TokenWithLocation

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

source

pub fn peek_nth_token(&self, n: usize) -> TokenWithLocation

Return nth non-whitespace token that has not yet been processed

source

pub fn peek_token_no_skip(&self) -> TokenWithLocation

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

source

pub fn peek_nth_token_no_skip(&self, n: usize) -> TokenWithLocation

Return nth token, possibly whitespace, that has not yet been processed.

source

pub fn next_token(&mut self) -> TokenWithLocation

Return the first non-whitespace 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.

source

pub fn next_token_no_skip(&mut self) -> Option<&TokenWithLocation>

Return the first unprocessed token, possibly whitespace.

source

pub fn prev_token(&mut self)

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.

source

pub fn expected<T>( &self, expected: &str, found: TokenWithLocation ) -> Result<T, ParserError>

Report found was encountered instead of expected

source

pub fn parse_keyword(&mut self, expected: Keyword) -> bool

If the current token is the expected keyword, consume it and returns true. Otherwise, no tokens are consumed and returns false.

source

pub fn parse_keyword_with_tokens( &mut self, expected: Keyword, tokens: &[Token] ) -> bool

If the current token is the expected keyword followed by specified tokens, consume them and returns true. Otherwise, no tokens are consumed and returns false.

Note that if the length of tokens is too long, this function will not be efficient as it does a loop on the tokens with peek_nth_token each time.

source

pub fn parse_keywords(&mut self, keywords: &[Keyword]) -> bool

If the current and subsequent tokens exactly match the keywords sequence, consume them and returns true. Otherwise, no tokens are consumed and returns false

source

pub fn parse_one_of_keywords(&mut self, keywords: &[Keyword]) -> Option<Keyword>

If the current token is one of the given keywords, consume the token and return the keyword that matches. Otherwise, no tokens are consumed and returns None.

source

pub fn expect_one_of_keywords( &mut self, keywords: &[Keyword] ) -> Result<Keyword, ParserError>

If the current token is one of the expected keywords, consume the token and return the keyword that matches. Otherwise, return an error.

source

pub fn expect_keyword(&mut self, expected: Keyword) -> Result<(), ParserError>

If the current token is the expected keyword, consume the token. Otherwise return an error.

source

pub fn expect_keywords( &mut self, expected: &[Keyword] ) -> Result<(), ParserError>

If the current and subsequent tokens exactly match the keywords sequence, consume them and returns Ok. Otherwise, return an Error.

source

pub fn consume_token(&mut self, expected: &Token) -> bool

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

source

pub fn consume_tokens(&mut self, tokens: &[Token]) -> bool

If the current and subsequent tokens exactly match the tokens sequence, consume them and returns true. Otherwise, no tokens are consumed and returns false

source

pub fn expect_token(&mut self, expected: &Token) -> Result<(), ParserError>

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

source

pub fn parse_projection(&mut self) -> Result<Vec<SelectItem>, ParserError>

Parse a comma-separated list of 1+ SelectItem

source

pub fn parse_comma_separated<T, F>( &mut self, f: F ) -> Result<Vec<T>, ParserError>
where F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,

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

source

pub fn parse_comma_separated0<T, F>( &mut self, f: F ) -> Result<Vec<T>, ParserError>
where F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,

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

source

pub fn parse_all_or_distinct(&mut self) -> Result<Option<Distinct>, ParserError>

Parse either ALL, DISTINCT or DISTINCT ON (...). Returns None if ALL is parsed and results in a ParserError if both ALL and DISTINCT are found.

source

pub fn parse_create(&mut self) -> Result<Statement, ParserError>

Parse a SQL CREATE statement

source

pub fn parse_create_secret( &mut self, or_replace: bool, temporary: bool, persistent: bool ) -> Result<Statement, ParserError>

See DuckDB Docs for more details.

source

pub fn parse_cache_table(&mut self) -> Result<Statement, ParserError>

Parse a CACHE TABLE statement

source

pub fn parse_as_query(&mut self) -> Result<(bool, Query), ParserError>

Parse ‘AS’ before as query,such as WITH XXX AS SELECT XXX oer CACHE TABLE AS SELECT XXX

source

pub fn parse_uncache_table(&mut self) -> Result<Statement, ParserError>

Parse a UNCACHE TABLE statement

source

pub fn parse_create_virtual_table(&mut self) -> Result<Statement, ParserError>

SQLite-specific CREATE VIRTUAL TABLE

source

pub fn parse_create_schema(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_create_database(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_optional_create_function_using( &mut self ) -> Result<Option<CreateFunctionUsing>, ParserError>

source

pub fn parse_create_function( &mut self, or_replace: bool, temporary: bool ) -> Result<Statement, ParserError>

source

pub fn parse_create_macro( &mut self, or_replace: bool, temporary: bool ) -> Result<Statement, ParserError>

source

pub fn parse_create_external_table( &mut self, or_replace: bool ) -> Result<Statement, ParserError>

source

pub fn parse_file_format(&mut self) -> Result<FileFormat, ParserError>

source

pub fn parse_analyze_format(&mut self) -> Result<AnalyzeFormat, ParserError>

source

pub fn parse_create_view( &mut self, or_replace: bool, temporary: bool ) -> Result<Statement, ParserError>

source

pub fn parse_create_role(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_drop(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_declare(&mut self) -> Result<Statement, ParserError>

Parse a DECLARE statement.

DECLARE name [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ]
    CURSOR [ { WITH | WITHOUT } HOLD ] FOR query

The syntax can vary significantly between warehouses. See the grammar on the warehouse specific function in such cases.

source

pub fn parse_big_query_declare(&mut self) -> Result<Statement, ParserError>

Parse a BigQuery DECLARE statement.

Syntax:

DECLARE variable_name[, ...] [{ <variable_type> | <DEFAULT expression> }];
source

pub fn parse_snowflake_declare(&mut self) -> Result<Statement, ParserError>

Parse a Snowflake DECLARE statement.

Syntax:

DECLARE
  [{ <variable_declaration>
     | <cursor_declaration>
     | <resultset_declaration>
     | <exception_declaration> }; ... ]

<variable_declaration>
<variable_name> [<type>] [ { DEFAULT | := } <expression>]

<cursor_declaration>
<cursor_name> CURSOR FOR <query>

<resultset_declaration>
<resultset_name> RESULTSET [ { DEFAULT | := } ( <query> ) ] ;

<exception_declaration>
<exception_name> EXCEPTION [ ( <exception_number> , '<exception_message>' ) ] ;
source

pub fn parse_mssql_declare(&mut self) -> Result<Statement, ParserError>

Parse a MsSql DECLARE statement.

Syntax:

DECLARE
source

pub fn parse_snowflake_variable_declaration_expression( &mut self ) -> Result<Option<DeclareAssignment>, ParserError>

Parses the assigned expression in a variable declaration.

Syntax:

[ { DEFAULT | := } <expression>]

https://docs.snowflake.com/en/sql-reference/snowflake-scripting/declare#variable-declaration-syntax

source

pub fn parse_mssql_variable_declaration_expression( &mut self ) -> Result<Option<DeclareAssignment>, ParserError>

Parses the assigned expression in a variable declaration.

Syntax:

[ = <expression>]
source

pub fn parse_fetch_statement(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_discard(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_create_index( &mut self, unique: bool ) -> Result<Statement, ParserError>

source

pub fn parse_create_extension(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_hive_distribution( &mut self ) -> Result<HiveDistributionStyle, ParserError>

source

pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError>

source

pub fn parse_row_format(&mut self) -> Result<HiveRowFormat, ParserError>

source

pub fn parse_create_table( &mut self, or_replace: bool, temporary: bool, global: Option<bool>, transient: bool ) -> Result<Statement, ParserError>

source

pub fn parse_optional_procedure_parameters( &mut self ) -> Result<Option<Vec<ProcedureParam>>, ParserError>

source

pub fn parse_columns( &mut self ) -> Result<(Vec<ColumnDef>, Vec<TableConstraint>), ParserError>

source

pub fn parse_procedure_param(&mut self) -> Result<ProcedureParam, ParserError>

source

pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError>

source

pub fn parse_optional_column_option( &mut self ) -> Result<Option<ColumnOption>, ParserError>

source

pub fn parse_referential_action( &mut self ) -> Result<ReferentialAction, ParserError>

source

pub fn parse_constraint_characteristics( &mut self ) -> Result<Option<ConstraintCharacteristics>, ParserError>

source

pub fn parse_optional_table_constraint( &mut self ) -> Result<Option<TableConstraint>, ParserError>

source

pub fn parse_options( &mut self, keyword: Keyword ) -> Result<Vec<SqlOption>, ParserError>

source

pub fn parse_options_with_keywords( &mut self, keywords: &[Keyword] ) -> Result<Vec<SqlOption>, ParserError>

source

pub fn parse_index_type(&mut self) -> Result<IndexType, ParserError>

source

pub fn parse_optional_using_then_index_type( &mut self ) -> Result<Option<IndexType>, ParserError>

Parse [USING {BTREE | HASH}]

source

pub fn parse_optional_indent(&mut self) -> Option<Ident>

Parse [ident], mostly ident is name, like: window_name, index_name, …

source

pub fn parse_index_type_display(&mut self) -> KeyOrIndexDisplay

source

pub fn parse_optional_index_option( &mut self ) -> Result<Option<IndexOption>, ParserError>

source

pub fn parse_index_options(&mut self) -> Result<Vec<IndexOption>, ParserError>

source

pub fn parse_sql_option(&mut self) -> Result<SqlOption, ParserError>

source

pub fn parse_partition(&mut self) -> Result<Partition, ParserError>

source

pub fn parse_alter_table_operation( &mut self ) -> Result<AlterTableOperation, ParserError>

source

pub fn parse_alter(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_alter_view(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_call(&mut self) -> Result<Statement, ParserError>

Parse a CALL procedure_name(arg1, arg2, ...) or CALL procedure_name statement

source

pub fn parse_copy(&mut self) -> Result<Statement, ParserError>

Parse a copy statement

source

pub fn parse_close(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_tsv(&mut self) -> Vec<Option<String>>

Parse a tab separated values in COPY payload

source

pub fn parse_tab_value(&mut self) -> Vec<Option<String>>

source

pub fn parse_value(&mut self) -> Result<Value, ParserError>

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

source

pub fn parse_number_value(&mut self) -> Result<Value, ParserError>

source

pub fn parse_literal_uint(&mut self) -> Result<u64, ParserError>

Parse an unsigned literal integer/long

source

pub fn parse_function_definition( &mut self ) -> Result<FunctionDefinition, ParserError>

source

pub fn parse_literal_string(&mut self) -> Result<String, ParserError>

Parse a literal string

source

pub fn parse_data_type(&mut self) -> Result<DataType, ParserError>

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

source

pub fn parse_string_values(&mut self) -> Result<Vec<String>, ParserError>

source

pub fn parse_identifier_with_alias( &mut self ) -> Result<IdentWithAlias, ParserError>

Strictly parse identifier AS identifier

source

pub fn parse_optional_alias( &mut self, reserved_kwds: &[Keyword] ) -> Result<Option<Ident>, ParserError>

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

source

pub fn parse_optional_table_alias( &mut self, reserved_kwds: &[Keyword] ) -> Result<Option<TableAlias>, ParserError>

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.

source

pub fn parse_object_name( &mut self, in_table_clause: bool ) -> Result<ObjectName, ParserError>

Parse a possibly qualified, possibly quoted identifier, e.g. foo or `myschema.“table”

The in_table_clause parameter indicates whether the object name is a table in a FROM, JOIN, or similar table clause. Currently, this is used only to support unquoted hyphenated identifiers in this context on BigQuery.

source

pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError>

Parse identifiers

source

pub fn parse_multipart_identifier(&mut self) -> Result<Vec<Ident>, ParserError>

Parse identifiers of form ident1[.identN]*

Similar in functionality to parse_identifiers, with difference being this function is much more strict about parsing a valid multipart identifier, not allowing extraneous tokens to be parsed, otherwise it fails.

For example:

use sqlparser::ast::Ident;
use sqlparser::dialect::GenericDialect;
use sqlparser::parser::Parser;

let dialect = GenericDialect {};
let expected = vec![Ident::new("one"), Ident::new("two")];

// expected usage
let sql = "one.two";
let mut parser = Parser::new(&dialect).try_with_sql(sql).unwrap();
let actual = parser.parse_multipart_identifier().unwrap();
assert_eq!(&actual, &expected);

// parse_identifiers is more loose on what it allows, parsing successfully
let sql = "one + two";
let mut parser = Parser::new(&dialect).try_with_sql(sql).unwrap();
let actual = parser.parse_identifiers().unwrap();
assert_eq!(&actual, &expected);

// expected to strictly fail due to + separator
let sql = "one + two";
let mut parser = Parser::new(&dialect).try_with_sql(sql).unwrap();
let actual = parser.parse_multipart_identifier().unwrap_err();
assert_eq!(
    actual.to_string(),
    "sql parser error: Unexpected token in identifier: +"
);
source

pub fn parse_identifier( &mut self, in_table_clause: bool ) -> Result<Ident, ParserError>

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

The in_table_clause parameter indicates whether the identifier is a table in a FROM, JOIN, or similar table clause. Currently, this is used only to support unquoted hyphenated identifiers in

source

pub fn parse_parenthesized_column_list( &mut self, optional: IsOptional, allow_empty: bool ) -> Result<Vec<Ident>, ParserError>

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

source

pub fn parse_precision(&mut self) -> Result<u64, ParserError>

source

pub fn parse_optional_precision(&mut self) -> Result<Option<u64>, ParserError>

source

pub fn parse_optional_character_length( &mut self ) -> Result<Option<CharacterLength>, ParserError>

source

pub fn parse_character_length(&mut self) -> Result<CharacterLength, ParserError>

source

pub fn parse_optional_precision_scale( &mut self ) -> Result<(Option<u64>, Option<u64>), ParserError>

source

pub fn parse_exact_number_optional_precision_scale( &mut self ) -> Result<ExactNumberInfo, ParserError>

source

pub fn parse_optional_type_modifiers( &mut self ) -> Result<Option<Vec<String>>, ParserError>

source

pub fn parse_delete(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_kill(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_explain( &mut self, describe_alias: DescribeAlias ) -> Result<Statement, ParserError>

source

pub fn parse_query(&mut self) -> Result<Query, ParserError>

Parse a query expression, i.e. a SELECT statement optionally preceded 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

source

pub fn parse_for_clause(&mut self) -> Result<Option<ForClause>, ParserError>

Parse a mssql FOR [XML | JSON | BROWSE] clause

source

pub fn parse_for_xml(&mut self) -> Result<ForClause, ParserError>

Parse a mssql FOR XML clause

source

pub fn parse_for_json(&mut self) -> Result<ForClause, ParserError>

Parse a mssql FOR JSON clause

source

pub fn parse_cte(&mut self) -> Result<Cte, ParserError>

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

source

pub fn parse_query_body( &mut self, precedence: u8 ) -> Result<SetExpr, ParserError>

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

If you need Box<SetExpr> then maybe there is sense to use parse_boxed_query_body due to prevent stack overflow in debug building(to reserve less memory on stack).

source

pub fn parse_set_operator(&mut self, token: &Token) -> Option<SetOperator>

source

pub fn parse_set_quantifier( &mut self, op: &Option<SetOperator> ) -> SetQuantifier

source

pub fn parse_select(&mut self) -> Result<Select, ParserError>

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

source

pub fn parse_connect_by(&mut self) -> Result<ConnectBy, ParserError>

source

pub fn parse_as_table(&mut self) -> Result<Table, ParserError>

Parse CREATE TABLE x AS TABLE y

source

pub fn parse_set(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_show(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_show_create(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_show_columns( &mut self, extended: bool, full: bool ) -> Result<Statement, ParserError>

source

pub fn parse_show_tables( &mut self, extended: bool, full: bool ) -> Result<Statement, ParserError>

source

pub fn parse_show_functions(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_show_collation(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_show_statement_filter( &mut self ) -> Result<Option<ShowStatementFilter>, ParserError>

source

pub fn parse_use(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError>

source

pub fn parse_table_factor(&mut self) -> Result<TableFactor, ParserError>

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

source

pub fn parse_table_version( &mut self ) -> Result<Option<TableVersion>, ParserError>

Parse a given table version specifier.

For now it only supports timestamp versioning for BigQuery and MSSQL dialects.

source

pub fn parse_json_table_column_def( &mut self ) -> Result<JsonTableColumn, ParserError>

Parses MySQL’s JSON_TABLE column definition. For example: id INT EXISTS PATH '$' DEFAULT '0' ON EMPTY ERROR ON ERROR

source

pub fn parse_derived_table_factor( &mut self, lateral: IsLateral ) -> Result<TableFactor, ParserError>

source

pub fn parse_pivot_table_factor( &mut self, table: TableFactor ) -> Result<TableFactor, ParserError>

source

pub fn parse_unpivot_table_factor( &mut self, table: TableFactor ) -> Result<TableFactor, ParserError>

source

pub fn parse_join_constraint( &mut self, natural: bool ) -> Result<JoinConstraint, ParserError>

source

pub fn parse_grant(&mut self) -> Result<Statement, ParserError>

Parse a GRANT statement.

source

pub fn parse_grant_revoke_privileges_objects( &mut self ) -> Result<(Privileges, GrantObjects), ParserError>

source

pub fn parse_grant_permission( &mut self ) -> Result<(Keyword, Option<Vec<Ident>>), ParserError>

source

pub fn parse_revoke(&mut self) -> Result<Statement, ParserError>

Parse a REVOKE statement

source

pub fn parse_replace(&mut self) -> Result<Statement, ParserError>

Parse an REPLACE statement

source

pub fn parse_insert(&mut self) -> Result<Statement, ParserError>

Parse an INSERT statement

source

pub fn parse_insert_partition( &mut self ) -> Result<Option<Vec<Expr>>, ParserError>

source

pub fn parse_update(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError>

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

source

pub fn parse_function_args(&mut self) -> Result<FunctionArg, ParserError>

source

pub fn parse_optional_args(&mut self) -> Result<Vec<FunctionArg>, ParserError>

source

pub fn parse_select_item(&mut self) -> Result<SelectItem, ParserError>

Parse a comma-delimited list of projections after SELECT

source

pub fn parse_wildcard_additional_options( &mut self ) -> Result<WildcardAdditionalOptions, ParserError>

Parse an WildcardAdditionalOptions information for wildcard select items.

If it is not possible to parse it, will return an option.

source

pub fn parse_optional_select_item_ilike( &mut self ) -> Result<Option<IlikeSelectItem>, ParserError>

Parse an Ilike information for wildcard select items.

If it is not possible to parse it, will return an option.

source

pub fn parse_optional_select_item_exclude( &mut self ) -> Result<Option<ExcludeSelectItem>, ParserError>

Parse an Exclude information for wildcard select items.

If it is not possible to parse it, will return an option.

source

pub fn parse_optional_select_item_except( &mut self ) -> Result<Option<ExceptSelectItem>, ParserError>

Parse an Except information for wildcard select items.

If it is not possible to parse it, will return an option.

source

pub fn parse_optional_select_item_rename( &mut self ) -> Result<Option<RenameSelectItem>, ParserError>

Parse a Rename information for wildcard select items.

source

pub fn parse_optional_select_item_replace( &mut self ) -> Result<Option<ReplaceSelectItem>, ParserError>

Parse a Replace information for wildcard select items.

source

pub fn parse_replace_elements( &mut self ) -> Result<ReplaceSelectElement, ParserError>

source

pub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError>

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

source

pub fn parse_top(&mut self) -> Result<Top, ParserError>

Parse a TOP clause, MSSQL equivalent of LIMIT, that follows after SELECT [DISTINCT].

source

pub fn parse_limit(&mut self) -> Result<Option<Expr>, ParserError>

Parse a LIMIT clause

source

pub fn parse_offset(&mut self) -> Result<Offset, ParserError>

Parse an OFFSET clause

source

pub fn parse_fetch(&mut self) -> Result<Fetch, ParserError>

Parse a FETCH clause

source

pub fn parse_lock(&mut self) -> Result<LockClause, ParserError>

Parse a FOR UPDATE/FOR SHARE clause

source

pub fn parse_values(&mut self, allow_empty: bool) -> Result<Values, ParserError>

source

pub fn parse_start_transaction(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_begin(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_end(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_transaction_modes( &mut self ) -> Result<Vec<TransactionMode>, ParserError>

source

pub fn parse_commit(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_rollback(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_commit_rollback_chain(&mut self) -> Result<bool, ParserError>

source

pub fn parse_rollback_savepoint(&mut self) -> Result<Option<Ident>, ParserError>

source

pub fn parse_deallocate(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_execute(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_prepare(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_unload(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_merge_clauses(&mut self) -> Result<Vec<MergeClause>, ParserError>

source

pub fn parse_merge(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_pragma(&mut self) -> Result<Statement, ParserError>

source

pub fn parse_install(&mut self) -> Result<Statement, ParserError>

INSTALL [extension_name]

source

pub fn parse_load(&mut self) -> Result<Statement, ParserError>

LOAD [extension_name]

source

pub fn parse_create_sequence( &mut self, temporary: bool ) -> Result<Statement, ParserError>

CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] <sequence_name>

See Postgres docs for more details.

source

pub fn index(&self) -> usize

The index of the first unprocessed token.

source

pub fn parse_named_window( &mut self ) -> Result<NamedWindowDefinition, ParserError>

source

pub fn parse_create_procedure( &mut self, or_alter: bool ) -> Result<Statement, ParserError>

source

pub fn parse_window_spec(&mut self) -> Result<WindowSpec, ParserError>

source

pub fn parse_create_type(&mut self) -> Result<Statement, ParserError>

source

pub fn into_tokens(self) -> Vec<TokenWithLocation>

Consume the parser and return its underlying token buffer

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> !RefUnwindSafe for Parser<'a>

§

impl<'a> !Send for Parser<'a>

§

impl<'a> !Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> !UnwindSafe for Parser<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.