pub struct Parser<'a> { /* private fields */ }Implementations§
Source§impl<'a> Parser<'a>
 
impl<'a> Parser<'a>
pub fn parse_alter_role(&mut self) -> Result<Statement, ParserError>
Source§impl<'a> Parser<'a>
 
impl<'a> Parser<'a>
Sourcepub fn new(dialect: &'a dyn Dialect) -> Self
 
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()?;Sourcepub fn with_recursion_limit(self, recursion_limit: usize) -> Self
 
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));Sourcepub fn with_options(self, options: ParserOptions) -> Self
 
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(_)));Sourcepub fn with_tokens_with_locations(self, tokens: Vec<TokenWithLocation>) -> Self
 
pub fn with_tokens_with_locations(self, tokens: Vec<TokenWithLocation>) -> Self
Reset this parser to parse the specified token stream
Sourcepub fn with_tokens(self, tokens: Vec<Token>) -> Self
 
pub fn with_tokens(self, tokens: Vec<Token>) -> Self
Reset this parser state to parse the specified tokens
Sourcepub fn try_with_sql(self, sql: &str) -> Result<Self, ParserError>
 
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
Sourcepub fn parse_statements(&mut self) -> Result<Vec<Statement>, ParserError>
 
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);Sourcepub fn parse_sql(
    dialect: &dyn Dialect,
    sql: &str,
) -> Result<Vec<Statement>, ParserError>
 
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);Sourcepub fn parse_statement(&mut self) -> Result<Statement, ParserError>
 
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.
pub fn parse_msck(&mut self) -> Result<Statement, ParserError>
pub fn parse_truncate(&mut self) -> Result<Statement, ParserError>
pub fn parse_attach_database(&mut self) -> Result<Statement, ParserError>
pub fn parse_analyze(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_wildcard_expr(&mut self) -> Result<WildcardExpr, ParserError>
 
pub fn parse_wildcard_expr(&mut self) -> Result<WildcardExpr, ParserError>
Parse a new expression including wildcard & qualified wildcard
Sourcepub fn parse_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_expr(&mut self) -> Result<Expr, ParserError>
Parse a new expression
Sourcepub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError>
 
pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError>
Parse tokens until the precedence changes
pub fn parse_interval_expr(&mut self) -> Result<Expr, ParserError>
Sourcepub fn get_next_interval_precedence(&self) -> Result<u8, ParserError>
 
pub fn get_next_interval_precedence(&self) -> Result<u8, ParserError>
Get the precedence of the next token With AND, OR, and XOR
pub fn parse_assert(&mut self) -> Result<Statement, ParserError>
pub fn parse_savepoint(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_prefix(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_prefix(&mut self) -> Result<Expr, ParserError>
Parse an expression prefix
pub fn parse_function(&mut self, name: ObjectName) -> Result<Expr, ParserError>
pub fn parse_time_functions( &mut self, name: ObjectName, ) -> Result<Expr, ParserError>
pub fn parse_window_frame_units( &mut self, ) -> Result<WindowFrameUnits, ParserError>
pub fn parse_window_frame(&mut self) -> Result<WindowFrame, ParserError>
Sourcepub fn parse_window_frame_bound(
    &mut self,
) -> Result<WindowFrameBound, ParserError>
 
pub fn parse_window_frame_bound( &mut self, ) -> Result<WindowFrameBound, ParserError>
Parse CURRENT ROW or { <positive number> | UNBOUNDED } { PRECEDING | FOLLOWING }
pub fn parse_case_expr(&mut self) -> Result<Expr, ParserError>
pub fn parse_optional_cast_format( &mut self, ) -> Result<Option<CastFormat>, ParserError>
Sourcepub fn parse_cast_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_cast_expr(&mut self) -> Result<Expr, ParserError>
Parse a SQL CAST function e.g. CAST(expr AS FLOAT)
Sourcepub fn parse_try_cast_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_try_cast_expr(&mut self) -> Result<Expr, ParserError>
Parse a SQL TRY_CAST function e.g. TRY_CAST(expr AS FLOAT)
Sourcepub fn parse_safe_cast_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_safe_cast_expr(&mut self) -> Result<Expr, ParserError>
Parse a BigQuery SAFE_CAST function e.g. SAFE_CAST(expr AS FLOAT64)
Sourcepub fn parse_exists_expr(&mut self, negated: bool) -> Result<Expr, ParserError>
 
pub fn parse_exists_expr(&mut self, negated: bool) -> Result<Expr, ParserError>
Parse a SQL EXISTS expression e.g. WHERE EXISTS(SELECT ...).
pub fn parse_extract_expr(&mut self) -> Result<Expr, ParserError>
pub fn parse_ceil_floor_expr( &mut self, is_ceil: bool, ) -> Result<Expr, ParserError>
pub fn parse_position_expr(&mut self) -> Result<Expr, ParserError>
pub fn parse_substring_expr(&mut self) -> Result<Expr, ParserError>
pub fn parse_overlay_expr(&mut self) -> Result<Expr, ParserError>
Sourcepub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError>
TRIM ([WHERE] ['text' FROM] 'text')
TRIM ('text')
TRIM(<expr>, [, characters]) -- only Snowflake or BigQuerypub fn parse_trim_where(&mut self) -> Result<TrimWhereField, ParserError>
Sourcepub fn parse_array_expr(&mut self, named: bool) -> Result<Expr, ParserError>
 
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]
pub fn parse_array_subquery(&mut self) -> Result<Expr, ParserError>
Sourcepub fn parse_listagg_expr(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_listagg_expr(&mut self) -> Result<Expr, ParserError>
Parse a SQL LISTAGG expression, e.g. LISTAGG(...) WITHIN GROUP (ORDER BY ...).
pub fn parse_array_agg_expr(&mut self) -> Result<Expr, ParserError>
pub fn parse_date_time_field(&mut self) -> Result<DateTimeField, ParserError>
pub fn parse_not(&mut self) -> Result<Expr, ParserError>
Sourcepub fn parse_match_against(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_match_against(&mut self) -> Result<Expr, ParserError>
Sourcepub fn parse_interval(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_interval(&mut self) -> Result<Expr, ParserError>
Parse an INTERVAL expression.
Some syntactically valid intervals:
INTERVAL '1' DAYINTERVAL '1-1' YEAR TO MONTHINTERVAL '1' SECONDINTERVAL '1:1:1.1' HOUR (5) TO SECOND (5)INTERVAL '1.1' SECOND (2, 2)INTERVAL '1:1' HOUR (5) TO MINUTE (5)- (MySql and BigQuey only):
INTERVAL 1 DAY 
Note that we do not currently attempt to parse the quoted value.
Sourcepub fn parse_infix(
    &mut self,
    expr: Expr,
    precedence: u8,
) -> Result<Expr, ParserError>
 
pub fn parse_infix( &mut self, expr: Expr, precedence: u8, ) -> Result<Expr, ParserError>
Parse an operator following an expression
Sourcepub fn parse_escape_char(&mut self) -> Result<Option<char>, ParserError>
 
pub fn parse_escape_char(&mut self) -> Result<Option<char>, ParserError>
parse the ESCAPE CHAR portion of LIKE, ILIKE, and SIMILAR TO
pub fn parse_array_index(&mut self, expr: Expr) -> Result<Expr, ParserError>
pub fn parse_map_access(&mut self, expr: Expr) -> Result<Expr, ParserError>
Sourcepub fn parse_in(
    &mut self,
    expr: Expr,
    negated: bool,
) -> Result<Expr, ParserError>
 
pub fn parse_in( &mut self, expr: Expr, negated: bool, ) -> Result<Expr, ParserError>
Parses the parens following the [ NOT ] IN operator
Sourcepub fn parse_between(
    &mut self,
    expr: Expr,
    negated: bool,
) -> Result<Expr, ParserError>
 
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
Sourcepub fn parse_pg_cast(&mut self, expr: Expr) -> Result<Expr, ParserError>
 
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
Sourcepub fn get_next_precedence(&self) -> Result<u8, ParserError>
 
pub fn get_next_precedence(&self) -> Result<u8, ParserError>
Get the precedence of the next token
Sourcepub fn peek_token(&self) -> TokenWithLocation
 
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)
Sourcepub fn peek_nth_token(&self, n: usize) -> TokenWithLocation
 
pub fn peek_nth_token(&self, n: usize) -> TokenWithLocation
Return nth non-whitespace token that has not yet been processed
Sourcepub fn next_token(&mut self) -> TokenWithLocation
 
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.
Sourcepub fn next_token_no_skip(&mut self) -> Option<&TokenWithLocation>
 
pub fn next_token_no_skip(&mut self) -> Option<&TokenWithLocation>
Return the first unprocessed token, possibly whitespace.
Sourcepub fn prev_token(&mut self)
 
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.
Sourcepub fn expected<T>(
    &self,
    expected: &str,
    found: TokenWithLocation,
) -> Result<T, ParserError>
 
pub fn expected<T>( &self, expected: &str, found: TokenWithLocation, ) -> Result<T, ParserError>
Report found was encountered instead of expected
Sourcepub fn parse_keyword(&mut self, expected: Keyword) -> bool
 
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.
Sourcepub fn parse_keywords(&mut self, keywords: &[Keyword]) -> bool
 
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
Sourcepub fn parse_one_of_keywords(&mut self, keywords: &[Keyword]) -> Option<Keyword>
 
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.
Sourcepub fn expect_one_of_keywords(
    &mut self,
    keywords: &[Keyword],
) -> Result<Keyword, ParserError>
 
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.
Sourcepub fn expect_keyword(&mut self, expected: Keyword) -> Result<(), ParserError>
 
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.
Sourcepub fn expect_keywords(
    &mut self,
    expected: &[Keyword],
) -> Result<(), ParserError>
 
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.
Sourcepub fn consume_token(&mut self, expected: &Token) -> bool
 
pub fn consume_token(&mut self, expected: &Token) -> bool
Consume the next token if it matches the expected token, otherwise return false
Sourcepub fn expect_token(&mut self, expected: &Token) -> Result<(), ParserError>
 
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
Sourcepub fn parse_projection(&mut self) -> Result<Vec<SelectItem>, ParserError>
 
pub fn parse_projection(&mut self) -> Result<Vec<SelectItem>, ParserError>
Parse a comma-separated list of 1+ SelectItem
Sourcepub fn parse_comma_separated<T, F>(
    &mut self,
    f: F,
) -> Result<Vec<T>, ParserError>
 
pub fn parse_comma_separated<T, F>( &mut self, f: F, ) -> Result<Vec<T>, ParserError>
Parse a comma-separated list of 1+ items accepted by F
Sourcepub fn parse_comma_separated0<T, F>(
    &mut self,
    f: F,
) -> Result<Vec<T>, ParserError>
 
pub fn parse_comma_separated0<T, F>( &mut self, f: F, ) -> Result<Vec<T>, ParserError>
Parse a comma-separated list of 0+ items accepted by F
Sourcepub fn parse_all_or_distinct(&mut self) -> Result<Option<Distinct>, ParserError>
 
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.
Sourcepub fn parse_create(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_create(&mut self) -> Result<Statement, ParserError>
Parse a SQL CREATE statement
Sourcepub fn parse_cache_table(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_cache_table(&mut self) -> Result<Statement, ParserError>
Parse a CACHE TABLE statement
Sourcepub fn parse_as_query(&mut self) -> Result<(bool, Query), ParserError>
 
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
Sourcepub fn parse_uncache_table(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_uncache_table(&mut self) -> Result<Statement, ParserError>
Parse a UNCACHE TABLE statement
Sourcepub fn parse_create_virtual_table(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_create_virtual_table(&mut self) -> Result<Statement, ParserError>
SQLite-specific CREATE VIRTUAL TABLE
pub fn parse_create_schema(&mut self) -> Result<Statement, ParserError>
pub fn parse_create_database(&mut self) -> Result<Statement, ParserError>
pub fn parse_optional_create_function_using( &mut self, ) -> Result<Option<CreateFunctionUsing>, ParserError>
pub fn parse_create_function( &mut self, or_replace: bool, temporary: bool, ) -> Result<Statement, ParserError>
pub fn parse_create_macro( &mut self, or_replace: bool, temporary: bool, ) -> Result<Statement, ParserError>
pub fn parse_create_external_table( &mut self, or_replace: bool, ) -> Result<Statement, ParserError>
pub fn parse_file_format(&mut self) -> Result<FileFormat, ParserError>
pub fn parse_analyze_format(&mut self) -> Result<AnalyzeFormat, ParserError>
pub fn parse_create_view( &mut self, or_replace: bool, temporary: bool, ) -> Result<Statement, ParserError>
pub fn parse_create_role(&mut self) -> Result<Statement, ParserError>
pub fn parse_drop(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_declare(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_declare(&mut self) -> Result<Statement, ParserError>
DECLARE name [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ]
    CURSOR [ { WITH | WITHOUT } HOLD ] FOR querypub fn parse_fetch_statement(&mut self) -> Result<Statement, ParserError>
pub fn parse_discard(&mut self) -> Result<Statement, ParserError>
pub fn parse_create_index( &mut self, unique: bool, ) -> Result<Statement, ParserError>
pub fn parse_hive_distribution( &mut self, ) -> Result<HiveDistributionStyle, ParserError>
pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError>
pub fn parse_row_format(&mut self) -> Result<HiveRowFormat, ParserError>
pub fn parse_create_table( &mut self, or_replace: bool, temporary: bool, global: Option<bool>, transient: bool, ) -> Result<Statement, ParserError>
pub fn parse_optional_procedure_parameters( &mut self, ) -> Result<Option<Vec<ProcedureParam>>, ParserError>
pub fn parse_columns( &mut self, ) -> Result<(Vec<ColumnDef>, Vec<TableConstraint>), ParserError>
pub fn parse_procedure_param(&mut self) -> Result<ProcedureParam, ParserError>
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError>
pub fn parse_optional_column_option( &mut self, ) -> Result<Option<ColumnOption>, ParserError>
pub fn parse_referential_action( &mut self, ) -> Result<ReferentialAction, ParserError>
pub fn parse_optional_table_constraint( &mut self, ) -> Result<Option<TableConstraint>, ParserError>
pub fn parse_options( &mut self, keyword: Keyword, ) -> Result<Vec<SqlOption>, ParserError>
pub fn parse_index_type(&mut self) -> Result<IndexType, ParserError>
pub fn parse_sql_option(&mut self) -> Result<SqlOption, ParserError>
pub fn parse_partition(&mut self) -> Result<Partition, ParserError>
pub fn parse_alter_table_operation( &mut self, ) -> Result<AlterTableOperation, ParserError>
pub fn parse_alter(&mut self) -> Result<Statement, ParserError>
pub fn parse_alter_view(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_copy(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_copy(&mut self) -> Result<Statement, ParserError>
Parse a copy statement
pub fn parse_close(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_tsv(&mut self) -> Vec<Option<String>>
 
pub fn parse_tsv(&mut self) -> Vec<Option<String>>
Parse a tab separated values in COPY payload
pub fn parse_tab_value(&mut self) -> Vec<Option<String>>
Sourcepub fn parse_value(&mut self) -> Result<Value, ParserError>
 
pub fn parse_value(&mut self) -> Result<Value, ParserError>
Parse a literal value (numbers, strings, date/time, booleans)
pub fn parse_number_value(&mut self) -> Result<Value, ParserError>
Sourcepub fn parse_literal_uint(&mut self) -> Result<u64, ParserError>
 
pub fn parse_literal_uint(&mut self) -> Result<u64, ParserError>
Parse an unsigned literal integer/long
pub fn parse_function_definition( &mut self, ) -> Result<FunctionDefinition, ParserError>
Sourcepub fn parse_literal_string(&mut self) -> Result<String, ParserError>
 
pub fn parse_literal_string(&mut self) -> Result<String, ParserError>
Parse a literal string
Sourcepub fn parse_map_key(&mut self) -> Result<Expr, ParserError>
 
pub fn parse_map_key(&mut self) -> Result<Expr, ParserError>
Parse a map key string
Sourcepub fn parse_data_type(&mut self) -> Result<DataType, ParserError>
 
pub fn parse_data_type(&mut self) -> Result<DataType, ParserError>
Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
pub fn parse_string_values(&mut self) -> Result<Vec<String>, ParserError>
Sourcepub fn parse_identifier_with_alias(
    &mut self,
) -> Result<IdentWithAlias, ParserError>
 
pub fn parse_identifier_with_alias( &mut self, ) -> Result<IdentWithAlias, ParserError>
Strictly parse identifier AS identifier
Sourcepub fn parse_optional_alias(
    &mut self,
    reserved_kwds: &[Keyword],
) -> Result<Option<Ident>, ParserError>
 
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
Sourcepub fn parse_optional_table_alias(
    &mut self,
    reserved_kwds: &[Keyword],
) -> Result<Option<TableAlias>, ParserError>
 
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.
Sourcepub fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>
 
pub fn parse_object_name(&mut self) -> Result<ObjectName, ParserError>
Parse a possibly qualified, possibly quoted identifier, e.g.
foo or `myschema.“table”
Sourcepub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError>
 
pub fn parse_identifiers(&mut self) -> Result<Vec<Ident>, ParserError>
Parse identifiers
Sourcepub fn parse_multipart_identifier(&mut self) -> Result<Vec<Ident>, ParserError>
 
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: +"
);Sourcepub fn parse_identifier(&mut self) -> Result<Ident, ParserError>
 
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError>
Parse a simple one-word identifier (possibly quoted, possibly a keyword)
Sourcepub fn parse_parenthesized_column_list(
    &mut self,
    optional: IsOptional,
    allow_empty: bool,
) -> Result<Vec<Ident>, ParserError>
 
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
pub fn parse_precision(&mut self) -> Result<u64, ParserError>
pub fn parse_optional_precision(&mut self) -> Result<Option<u64>, ParserError>
pub fn parse_optional_character_length( &mut self, ) -> Result<Option<CharacterLength>, ParserError>
pub fn parse_character_length(&mut self) -> Result<CharacterLength, ParserError>
pub fn parse_optional_precision_scale( &mut self, ) -> Result<(Option<u64>, Option<u64>), ParserError>
pub fn parse_exact_number_optional_precision_scale( &mut self, ) -> Result<ExactNumberInfo, ParserError>
pub fn parse_optional_type_modifiers( &mut self, ) -> Result<Option<Vec<String>>, ParserError>
pub fn parse_delete(&mut self) -> Result<Statement, ParserError>
pub fn parse_kill(&mut self) -> Result<Statement, ParserError>
pub fn parse_explain( &mut self, describe_alias: bool, ) -> Result<Statement, ParserError>
Sourcepub fn parse_query(&mut self) -> Result<Query, ParserError>
 
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
Sourcepub fn parse_cte(&mut self) -> Result<Cte, ParserError>
 
pub fn parse_cte(&mut self) -> Result<Cte, ParserError>
Parse a CTE (alias [( col1, col2, ... )] AS (subquery))
Sourcepub fn parse_query_body(
    &mut self,
    precedence: u8,
) -> Result<SetExpr, ParserError>
 
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_bodypub fn parse_set_operator(&mut self, token: &Token) -> Option<SetOperator>
pub fn parse_set_quantifier( &mut self, op: &Option<SetOperator>, ) -> SetQuantifier
Sourcepub fn parse_select(&mut self) -> Result<Select, ParserError>
 
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
Sourcepub fn parse_as_table(&mut self) -> Result<Table, ParserError>
 
pub fn parse_as_table(&mut self) -> Result<Table, ParserError>
Parse CREATE TABLE x AS TABLE y
pub fn parse_set(&mut self) -> Result<Statement, ParserError>
pub fn parse_show(&mut self) -> Result<Statement, ParserError>
pub fn parse_show_create(&mut self) -> Result<Statement, ParserError>
pub fn parse_show_columns( &mut self, extended: bool, full: bool, ) -> Result<Statement, ParserError>
pub fn parse_show_tables( &mut self, extended: bool, full: bool, ) -> Result<Statement, ParserError>
pub fn parse_show_functions(&mut self) -> Result<Statement, ParserError>
pub fn parse_show_collation(&mut self) -> Result<Statement, ParserError>
pub fn parse_show_statement_filter( &mut self, ) -> Result<Option<ShowStatementFilter>, ParserError>
pub fn parse_use(&mut self) -> Result<Statement, ParserError>
pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError>
Sourcepub fn parse_table_factor(&mut self) -> Result<TableFactor, ParserError>
 
pub fn parse_table_factor(&mut self) -> Result<TableFactor, ParserError>
A table name or a parenthesized subquery, followed by optional [AS] alias
Sourcepub fn parse_table_version(
    &mut self,
) -> Result<Option<TableVersion>, ParserError>
 
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.
pub fn parse_derived_table_factor( &mut self, lateral: IsLateral, ) -> Result<TableFactor, ParserError>
pub fn parse_pivot_table_factor( &mut self, table: TableFactor, ) -> Result<TableFactor, ParserError>
pub fn parse_unpivot_table_factor( &mut self, table: TableFactor, ) -> Result<TableFactor, ParserError>
pub fn parse_join_constraint( &mut self, natural: bool, ) -> Result<JoinConstraint, ParserError>
Sourcepub fn parse_grant(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_grant(&mut self) -> Result<Statement, ParserError>
Parse a GRANT statement.
pub fn parse_grant_revoke_privileges_objects( &mut self, ) -> Result<(Privileges, GrantObjects), ParserError>
pub fn parse_grant_permission( &mut self, ) -> Result<(Keyword, Option<Vec<Ident>>), ParserError>
Sourcepub fn parse_revoke(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_revoke(&mut self) -> Result<Statement, ParserError>
Parse a REVOKE statement
Sourcepub fn parse_insert(&mut self) -> Result<Statement, ParserError>
 
pub fn parse_insert(&mut self) -> Result<Statement, ParserError>
Parse an INSERT statement
pub fn parse_update(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_assignment(&mut self) -> Result<Assignment, ParserError>
 
pub fn parse_assignment(&mut self) -> Result<Assignment, ParserError>
Parse a var = expr assignment, used in an UPDATE statement
pub fn parse_function_args(&mut self) -> Result<FunctionArg, ParserError>
pub fn parse_optional_args(&mut self) -> Result<Vec<FunctionArg>, ParserError>
pub fn parse_optional_args_with_orderby( &mut self, ) -> Result<(Vec<FunctionArg>, Vec<OrderByExpr>), ParserError>
Sourcepub fn parse_select_item(&mut self) -> Result<SelectItem, ParserError>
 
pub fn parse_select_item(&mut self) -> Result<SelectItem, ParserError>
Parse a comma-delimited list of projections after SELECT
Sourcepub fn parse_wildcard_additional_options(
    &mut self,
) -> Result<WildcardAdditionalOptions, ParserError>
 
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.
Sourcepub fn parse_optional_select_item_exclude(
    &mut self,
) -> Result<Option<ExcludeSelectItem>, ParserError>
 
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.
Sourcepub fn parse_optional_select_item_except(
    &mut self,
) -> Result<Option<ExceptSelectItem>, ParserError>
 
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.
Sourcepub fn parse_optional_select_item_rename(
    &mut self,
) -> Result<Option<RenameSelectItem>, ParserError>
 
pub fn parse_optional_select_item_rename( &mut self, ) -> Result<Option<RenameSelectItem>, ParserError>
Parse a Rename information for wildcard select items.
Sourcepub fn parse_optional_select_item_replace(
    &mut self,
) -> Result<Option<ReplaceSelectItem>, ParserError>
 
pub fn parse_optional_select_item_replace( &mut self, ) -> Result<Option<ReplaceSelectItem>, ParserError>
Parse a Replace information for wildcard select items.
pub fn parse_replace_elements( &mut self, ) -> Result<ReplaceSelectElement, ParserError>
Sourcepub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError>
 
pub fn parse_order_by_expr(&mut self) -> Result<OrderByExpr, ParserError>
Parse an expression, optionally followed by ASC or DESC (used in ORDER BY)
Sourcepub fn parse_top(&mut self) -> Result<Top, ParserError>
 
pub fn parse_top(&mut self) -> Result<Top, ParserError>
Parse a TOP clause, MSSQL equivalent of LIMIT,
that follows after SELECT [DISTINCT].
Sourcepub fn parse_limit(&mut self) -> Result<Option<Expr>, ParserError>
 
pub fn parse_limit(&mut self) -> Result<Option<Expr>, ParserError>
Parse a LIMIT clause
Sourcepub fn parse_offset(&mut self) -> Result<Offset, ParserError>
 
pub fn parse_offset(&mut self) -> Result<Offset, ParserError>
Parse an OFFSET clause
Sourcepub fn parse_fetch(&mut self) -> Result<Fetch, ParserError>
 
pub fn parse_fetch(&mut self) -> Result<Fetch, ParserError>
Parse a FETCH clause
Sourcepub fn parse_lock(&mut self) -> Result<LockClause, ParserError>
 
pub fn parse_lock(&mut self) -> Result<LockClause, ParserError>
Parse a FOR UPDATE/FOR SHARE clause
pub fn parse_values(&mut self, allow_empty: bool) -> Result<Values, ParserError>
pub fn parse_start_transaction(&mut self) -> Result<Statement, ParserError>
pub fn parse_begin(&mut self) -> Result<Statement, ParserError>
pub fn parse_transaction_modes( &mut self, ) -> Result<Vec<TransactionMode>, ParserError>
pub fn parse_commit(&mut self) -> Result<Statement, ParserError>
pub fn parse_rollback(&mut self) -> Result<Statement, ParserError>
pub fn parse_commit_rollback_chain(&mut self) -> Result<bool, ParserError>
pub fn parse_deallocate(&mut self) -> Result<Statement, ParserError>
pub fn parse_execute(&mut self) -> Result<Statement, ParserError>
pub fn parse_prepare(&mut self) -> Result<Statement, ParserError>
pub fn parse_merge_clauses(&mut self) -> Result<Vec<MergeClause>, ParserError>
pub fn parse_merge(&mut self) -> Result<Statement, ParserError>
pub fn parse_pragma(&mut self) -> Result<Statement, ParserError>
Sourcepub fn parse_create_sequence(
    &mut self,
    temporary: bool,
) -> Result<Statement, ParserError>
 
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.