Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse MySQL create table with NOW() default #2820

Closed
3 tasks done
jasonaowen opened this issue Mar 9, 2022 · 1 comment · Fixed by #2825
Closed
3 tasks done

Parse MySQL create table with NOW() default #2820

jasonaowen opened this issue Mar 9, 2022 · 1 comment · Fixed by #2825
Labels
bug Something isn't working mysql

Comments

@jasonaowen
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Parsing a CREATE TABLE statement fails if a column has a default of NOW().

Expected Behaviour

SQLFluff should be able to parse the valid, executable SQL and report on any style guide violations it finds.

Observed Behaviour

Instead, SQLFluff throws a parse error:

Line 1, Position 1: Found unparsable section: 'CREATE TABLE a ( t TIMESTAMP DEFAULT NOW...'

How to reproduce

With default-timestamp.sql as

CREATE TABLE a ( t TIMESTAMP DEFAULT NOW() );

running SQLFluff returns a parse error:

$ sqlfluff parse --verbose --ignore-local-config --dialect mysql default-timestamp.sql 
==== sqlfluff ====
sqlfluff:               0.11.0 python:                 3.8.10
implementation:        cpython dialect:                 mysql
verbosity:                   1 templater:               jinja

=== [ path: default-timestamp.sql ] ===

[L:  1, P:  1]      |file:
[L:  1, P:  1]      |    statement:
[L:  1, P:  1]      |        unparsable:                                           !! Expected: 'StatementSegment'
[L:  1, P:  1]      |            raw:                                              'CREATE'
[L:  1, P:  7]      |            whitespace:                                       ' '
[L:  1, P:  8]      |            raw:                                              'TABLE'
[L:  1, P: 13]      |            whitespace:                                       ' '
[L:  1, P: 14]      |            raw:                                              'a'
[L:  1, P: 15]      |            whitespace:                                       ' '
[L:  1, P: 16]      |            bracketed:
[L:  1, P: 16]      |                start_bracket:                                '('
[L:  1, P: 17]      |                whitespace:                                   ' '
[L:  1, P: 18]      |                raw:                                          't'
[L:  1, P: 19]      |                whitespace:                                   ' '
[L:  1, P: 20]      |                raw:                                          'TIMESTAMP'
[L:  1, P: 29]      |                whitespace:                                   ' '
[L:  1, P: 30]      |                raw:                                          'DEFAULT'
[L:  1, P: 37]      |                whitespace:                                   ' '
[L:  1, P: 38]      |                raw:                                          'NOW'
[L:  1, P: 41]      |                bracketed:
[L:  1, P: 41]      |                    start_bracket:                            '('
[L:  1, P: 42]      |                    end_bracket:                              ')'
[L:  1, P: 43]      |                whitespace:                                   ' '
[L:  1, P: 44]      |                end_bracket:                                  ')'
[L:  1, P: 45]      |    statement_terminator:                                     ';'
[L:  1, P: 46]      |    newline:                                                  '\n'

==== parsing violations ====
L:   1 | P:   1 |  PRS | Line 1, Position 1: Found unparsable section: 'CREATE TABLE a ( t
                       | TIMESTAMP DEFAULT NOW...'

Dialect

MySQL

Version

sqlfluff, version 0.11.0
Python 3.8.10

Configuration

All defaults

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

@jasonaowen jasonaowen added the bug Something isn't working label Mar 9, 2022
@tunetheweb tunetheweb mentioned this issue Mar 9, 2022
1 task
@jasonaowen
Copy link
Author

Thanks for the quick fix, @tunetheweb, and the quick review by @barrywhart!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mysql
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants