Parsing error

Such error implies two states:

  1. query contains invalid syntax (it is up to you to correct it)
  2. query is valid however our SQL parser didn't recognized the syntax (it is our job to fix it)

How do I know my SQL query is valid?

If you can execute it on your database then it is valid.

Do I need to report a Parsing error?

Nope, as long as you are a paying customer. We are monitoring everything that goes through our SQL parser. A ticket is in such case raised automatically and our engineers are notified.

If you are evaluating SQLdep and parsing error holds you back, feel free to contact us.

How quickly do you fix parsing errors?

In most cases we fix parsing errors within 48 hours.

SQL Parsing explained (to educate our users) 

Parsing actually consists from two steps, that is (a) lexical analysis (b) parsing step.

Lexical analysis

Consider this simple SQL query:

SELECT ACC_ID
FROM ACCOUNTS

Lexer's job is to take the input data and create tokens from it. Input is read character by character and when empty space is encountered the token is created. 

1st token SELECT
2nd token ACC_ID
3rd token FROM
4th token ACCOUNTS 

Lexer enriches every token with additional information like its position in the input data. It also verifies whether token is a keyword or constant (literal or number).

Parser

Parser's job is to provide more detailed information about each token and create a tree structure from it. The structure is called Abstract Syntax Tree which is afterwards crawled by analyser (that's a standalone step).

Before compiling the parser a grammar needs to be created. Grammar is defined by each database vendor (thus the nuances exists) and it describes how the SQL syntax looks like. Once the grammar is ready the parser generator compiles the final parser.

Parsing explained on a example

DROP TABLE IF EXISTS CUSTOMERS 

Consider following grammar while only 2 commands are allowed.

Lexer prepares tokens

1st token DROP
2nd token TABLE
3rd token IF
4th token EXISTS
5th token CUSTOMERS 

Parser (top-down)

  1. takes token DROP and identifies that both commands are eligible
  2. takes token TABLE and thus discards DROP TRIGGER and selects DROP TABLE 
  3. takes token IF and confirms it fits the grammar rules
  4. takes token EXISTS  and confirms it fits the grammar rules as well
  5. takes token CUSTOMERS however the only acceptable value is EXISTS thefore it throws parsing error

In each steps we  define whether that information should be stored. For example first 2 tokens (DROP TABLE ) helps us to identify the statement thus it is stored. Third and forth tokens have no information value for us and are ignored. Fifth token is however identifies particular table and is stored.

The resulting structure is called Abstract Syntax Tree. It is used as an input for the final step which is semantic analysis (not covered by this article).

Did this answer your question?