Skip to content

BigQuery dialect fails to parse PRIMARY KEY NOT ENFORCED #6462

@Idane

Description

@Idane

Search before asking

  • I searched the issues and found no similar issues.

What Happened

When creating a table with the PRIMARY KEY NOT ENFORCED expression, parsing fails. PK enforcement are not supported in BigQuery, and running the query without NOT ENFORCED will fail and produce an error. Therefore, it must be added when specifying a primary key.

Expected Behaviour

Should parse the query correctly

Observed Behaviour

Result:

[L:  1, P:  1]      |file:
[L:  1, P:  1]      |    statement:
[L:  1, P:  1]      |        create_table_statement:
[L:  1, P:  1]      |            keyword:                                          'CREATE'
[L:  1, P:  7]      |            whitespace:                                       ' '
[L:  1, P:  8]      |            keyword:                                          'TABLE'
[L:  1, P: 13]      |            whitespace:                                       ' '
[L:  1, P: 14]      |            table_reference:
[L:  1, P: 14]      |                quoted_identifier:                            '`some_dataset.some_table`'
[L:  1, P: 39]      |    whitespace:                                               ' '
[L:  1, P: 40]      |    unparsable:                                               !! Expected: 'Nothing else in FileSegment.'
[L:  1, P: 40]      |        start_bracket:                                        '('
[L:  1, P: 41]      |        newline:                                              '\n'
[L:  2, P:  1]      |        whitespace:                                           '    '
[L:  2, P:  5]      |        word:                                                 'id'
[L:  2, P:  7]      |        whitespace:                                           ' '
[L:  2, P:  8]      |        word:                                                 'STRING'
[L:  2, P: 14]      |        whitespace:                                           ' '
[L:  2, P: 15]      |        word:                                                 'NOT'
[L:  2, P: 18]      |        whitespace:                                           ' '
[L:  2, P: 19]      |        word:                                                 'NULL'
[L:  2, P: 23]      |        whitespace:                                           ' '
[L:  2, P: 24]      |        word:                                                 'PRIMARY'
[L:  2, P: 31]      |        whitespace:                                           ' '
[L:  2, P: 32]      |        word:                                                 'KEY'
[L:  2, P: 35]      |        whitespace:                                           ' '
[L:  2, P: 36]      |        word:                                                 'NOT'
[L:  2, P: 39]      |        whitespace:                                           ' '
[L:  2, P: 40]      |        word:                                                 'ENFORCED'
[L:  2, P: 48]      |        newline:                                              '\n'
[L:  3, P:  1]      |        end_bracket:                                          ')'
[L:  3, P:  2]      |    [META] end_of_file:

==== parsing violations ====
L:   1 | P:  40 |  PRS | Line 1, Position 40: Found unparsable section: '(\n    id STRING
                       | NOT NULL PRIMARY KEY NOT...'
WARNING: Parsing errors found and dialect is set to 'bigquery'. Have you configured your dialect correctly?

How to reproduce

Reproducible query:

CREATE TABLE `some_dataset.some_table` (
    id STRING NOT NULL PRIMARY KEY NOT ENFORCED
)

Dialect

BigQuery

Version

3.2.5

Configuration

[sqlfluff]
dialect = bigquery

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

    bigqueryIssues relating to the BigQuery dialectbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions