sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.31k stars 399 forks source link

Error formatting MariaDB CASE STATEMENT #780

Open Silver-Fang opened 1 week ago

Silver-Fang commented 1 week ago

Describe your problem

This code is copied from the MariaDB documentation so there should be no syntax errors:

  CASE v
    WHEN 2 THEN SELECT v;
    WHEN 3 THEN SELECT 0;
    ELSE BEGIN END;
  END CASE;

An Unexpected Error Occurred Parse error at token: SELECT at line 2 column 17 Unexpected RESERVED_SELECT token:

Which SQL dialect does this apply to?

MariaDB

Which SQL dialect is configured in your VSCode extension settings?

MariaDB

Version of the VSCode extension

4.1.1

I have tried to reproduce this issue on the demo page, and it

nene commented 1 week ago

Thanks for reporting. Unfortunately the support of procedural SQL in SQL Formatter is pretty weak.

The specific problem happens because it really only understand the SQL CASE expression, but has next to no support for CASE statement.

Fixing this is more akin to feature development and I've mostly stopped doing new feature development on SQL Formatter.

I might suggest you instead give a try to prettier-plugin-sql-cst which has better MariaDB/MySQL support, including support for the above CASE statement.

Silver-Fang commented 6 days ago

Thanks for reporting. Unfortunately the support of procedural SQL in SQL Formatter is pretty weak.

The specific problem happens because it really only understand the SQL CASE expression, but has next to no support for CASE statement.

Fixing this is more akin to feature development and I've mostly stopped doing new feature development on SQL Formatter.

I might suggest you instead give a try to prettier-plugin-sql-cst which has better MariaDB/MySQL support, including support for the above CASE statement.

I can't identify whether the prettier-plugin-sql-cst you provide can be used for in VSCode?

nene commented 6 days ago

You can use it through the VSCode Prettier extension as it's just a plugin for Prettier.

Silver-Fang commented 5 days ago

Fine. CREATE PROCEDURE and UNSIGNED is also not supported. 😭