Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-8943

Syntax check for SQL files or SQL queries

Details

    Description

      (I chose an issue type "epic", but this is a feature request)

      It would be nice if it were possible to check the syntax of a file, for example as part of a pre-commit hook in a version control system.

      I tried to do something like that by abusing the --one-database option of the command-line client:

      mysql -u automatic -o mysql < developmentrevival.sql

      (Where the .sql file starts with a USE statement that mentions another database than "mysql")

      In the query log, I see only the (harmless) SET statements in that file, so this workaround does not influence the wrong database, but alas it does not fail on syntax errors either.

      It would be nice if there were a --lint or --dry-run option to do a syntax check.

      Attachments

        Issue Links

          Activity

            While a linter using the same parser as the server would be more reliable, I started using sqlfluff in my projects for that purpose which works well enough, and doubles as a pretty printer. There's still corner cases it doesn't handle correctly, but it sees very active development so things might improve over time.

            pprkut Heinz Wiesinger added a comment - While a linter using the same parser as the server would be more reliable, I started using sqlfluff in my projects for that purpose which works well enough, and doubles as a pretty printer. There's still corner cases it doesn't handle correctly, but it sees very active development so things might improve over time.

            People

              Unassigned Unassigned
              donquichote BitSmid
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.