sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

Error formatting MariaDB CASE STATEMENT

Open Ebola-Chan-bot opened this issue 1 year ago • 4 comments

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

  • Reproduces

Ebola-Chan-bot avatar Sep 16 '24 00:09 Ebola-Chan-bot

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.

nene avatar Sep 16 '24 05:09 nene

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?

Ebola-Chan-bot avatar Sep 18 '24 01:09 Ebola-Chan-bot

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

nene avatar Sep 18 '24 04:09 nene

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

Ebola-Chan-bot avatar Sep 19 '24 02:09 Ebola-Chan-bot