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

MySQL triggers reporting an unparseable section for trigger SET statements #5862

Open
2 of 3 tasks
acdha opened this issue May 8, 2024 · 0 comments
Open
2 of 3 tasks
Labels
bug Something isn't working mysql

Comments

@acdha
Copy link

acdha commented May 8, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I am attempting to clean up a large MySQL application which uses triggers for compatibility with an older application. This obviously runs hard into #3599 but I noticed another oddity with SET statements in those triggers - here's a highly-reduced example:

CREATE TRIGGER tr_downloads_i_copy_new_fields BEFORE INSERT
ON downloads
FOR EACH ROW BEGIN

SET NEW.createdate = UNIX_TIMESTAMP(NEW.createdate_m);

END

A little code golfing suggests that the problem is using the SET NEW.<column> form since SQLFluff works fine the more common SET @variable form. As far as I know, that's the only way to do that in MySQL and it's what they use in the examples:

https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

Expected Behaviour

The body of the trigger would be formatted

Observed Behaviour

== [test.sql] FAIL                                                                          
L:   1 | P:   1 |  PRS | Line 1, Position 1: Found unparsable section: 'CREATE
                       | TRIGGER tr_downloadao_i_copy_new_...'
WARNING: Parsing errors found and dialect is set to 'mysql'. Have you configured your dialect correctly?

How to reproduce

sqlfluff lint

Dialect

mysql

Version

3.0.6

Configuration

[sqlfluff]
dialect = mysql
max_line_length = 120
exclude_rules = L013

[sqlfluff:indentation]
tab_space_size = 4

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper
[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper

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

@acdha acdha added the bug Something isn't working label May 8, 2024
@github-actions github-actions bot added the mysql label May 8, 2024
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

No branches or pull requests

1 participant