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

Support of MySQL database selection #902

Closed
Tiross opened this issue Mar 27, 2021 · 2 comments · Fixed by #950
Closed

Support of MySQL database selection #902

Tiross opened this issue Mar 27, 2021 · 2 comments · Fixed by #950
Assignees
Labels
dialect Issue related to general dialect support. Use dialect-specific label instead where appropriate enhancement New feature or request mysql parser Means adding functionality to the parser or dialects

Comments

@Tiross
Copy link

Tiross commented Mar 27, 2021

Hello,

As I use many MySQL procedures, I used to stored them in SQL file in order to import them into my server when needed.

Every files start with the 2 same lines

CREATE DATABASE IF NOT EXISTS my_db;
USE my_db;

These 2 lines cause a PSR error, SQLFluff does not parse USE my_db.

echo 'CREATE DATABASE IF NOT EXISTS my_db; USE my_db;' | sqlfluff lint --dialect mysql -
== [stdin] FAIL
L:   1 | P:  38 |  PRS | Found unparsable section: 'USE my_db'

Online fluff

Is it possible to support USE ?

Thank you

@Tiross Tiross added the enhancement New feature or request label Mar 27, 2021
@dmateusp dmateusp added dialect Issue related to general dialect support. Use dialect-specific label instead where appropriate mysql parser Means adding functionality to the parser or dialects labels Apr 11, 2021
@dmateusp dmateusp self-assigned this Apr 11, 2021
@dmateusp
Copy link
Contributor

hi @Tiross, thanks for raising the issue!

I'm going to take that on, I'd like to also support the variations from Snowflake:

https://docs.snowflake.com/en/sql-reference/sql/use.html

USE ROLE <name>

USE WAREHOUSE <name>

USE [ DATABASE ] <name>

USE [ SCHEMA ] [<db_name>.]<name>

@dmateusp
Copy link
Contributor

Actually we already have logic to support the Snowflake USE statements, so I'm going to extract it into our base (ANSI) dialect

dmateusp pushed a commit to dmateusp/sqlfluff that referenced this issue Apr 12, 2021
dmateusp pushed a commit that referenced this issue Apr 12, 2021
* Move USE statement from Snowflake to ANSI ⏪

* Add parser tests for USE statements in MySQL and Snowflake ✅

* Update CHANGELOG ✏️

* Fix due to decorator removed when merging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect Issue related to general dialect support. Use dialect-specific label instead where appropriate enhancement New feature or request mysql parser Means adding functionality to the parser or dialects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants