Skip to content

[FORMATTING] [MySQL] Newline after USE keyword causes syntax error #456

@raahii

Description

@raahii

Input data

Which SQL and options did you provide as input?

CREATE DATABASE IF NOT EXISTS sample;

USE sample;
sql-formatter -l mysql

Expected Output

CREATE DATABASE
  IF NOT EXISTS sample;

USE sample;

Actual Output

CREATE DATABASE
  IF NOT EXISTS sample;

USE
  sample;

Why?

The current formatting result causes syntax error on MySQL 8.0.30.
It seems should not place \n between USE and <DB NAME>.

$ mysql --version
mysql  Ver 8.0.30 for Linux on x86_64 (MySQL Community Server - GPL)

$ cat test.sql
CREATE DATABASE
  IF NOT EXISTS sample;

USE
  sample;
$ mysql < test.sql
ERROR at line 4: USE must be followed by a database name
ERROR 1064 (42000) at line 5: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sample' at line 1

Usage

  • How are you calling / using the library?
    • cat test.sql | sql-formatter -l mysql
  • What SQL language(s) does this apply to?
    • mysql
  • Which SQL Formatter version are you using?
    • 10.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions