Skip to content

[TSQL] Error parsing statements with the words Class and Property #5743

@martinswan

Description

@martinswan

Search before asking

  • I searched the issues and found no similar issues.

What Happened

SQL code that we have in or system contains unbracketed references to fields named "Class" and "Property". The code runs fine in the system, but SQLFluff is not able to parse this code.

Expected Behaviour

I would expect the following code to run without error:

import sqlfluff

query = f"""
SELECT
  Class
, Property
FROM MyDatabase.MySchema.MyTable
"""

sqlfluff.parse(query, dialect='tsql')

The code does run without error if you update it to include brackets around the field names likes so:

query = f"""
SELECT
  [Class]
, [Property]
FROM MyDatabase.MySchema.MyTable
"""

sqlfluff.parse(query, dialect='tsql')

Observed Behaviour

Instead of the code running without error, I get the following error:

sqlfluff.api.simple.APIParsingError: Found 1 issues while parsing string.
Line 2, Position 1: Found unparsable section: 'SELECT\n  Class\n, Property\nFROM MyDatabas...'

How to reproduce

Run the following code to get this error:

import sqlfluff

query = f"""
SELECT
  Class
, Property
FROM MyDatabase.MySchema.MyTable
"""

sqlfluff.parse(query, dialect='tsql')

Dialect

tsql

Version

sqlfluff 2.3.5
python 3.12.1

Configuration

(no configuration)

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingt-sqlIssues related to the T-SQL/TSQL/Transact SQL dialect

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions