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 Chinese parenthesis characters in MySQL #610

Open
jiangyayu opened this issue Jun 13, 2023 · 9 comments
Open

Support Chinese parenthesis characters in MySQL #610

jiangyayu opened this issue Jun 13, 2023 · 9 comments
Labels

Comments

@jiangyayu
Copy link

jiangyayu commented Jun 13, 2023

Input data

SELECT `时间` as "时间",SUM(进度(计划完成率)) as "SUM(`进度(计划完成率)`)" FROM ds_upload_19 WHERE 1=1 GROUP BY `时间` LIMIT 1000 

Expected Output

SELECT
  `时间` as "时间",
  SUM(进 度 ( 计 划 完 成 率 )) as "SUM(`进度(计划完成率)`)"
FROM
  ds_upload_19
WHERE
  1 = 1
GROUP BY
  `时间`
LIMIT
  1000

Actual Output

SELECT `时间` as "时间",SUM(进度(计划完成率)) as "SUM(`进度(计划完成率)`)" FROM ds_upload_19 WHERE 1=1 GROUP BY `时间` LIMIT 1000 

Usage

  • How are you calling / using the library?
  • What SQL language(s) does this apply to?
  • Which SQL Formatter version are you using?
@jiangyayu jiangyayu added the bug label Jun 13, 2023
@grantwforsythe
Copy link
Contributor

Are you able to provide more context?

@nene
Copy link
Collaborator

nene commented Jun 14, 2023

The formatter works as expected. -- starts a line comment in SQL.

This is also demonstrated in how Github syntax-highlights this code (grayed out as a comment).

@nene nene closed this as completed Jun 14, 2023
@jiangyayu
Copy link
Author

jiangyayu commented Jun 14, 2023

sorry, it's my fault. The correct SQL is SELECT 时间 as "时间",SUM(进度(计划完成率)) as "SUM(进度(计划完成率))" FROM ds_upload_19 WHERE 1=1 GROUP BY 时间 LIMIT 1000, without --

@jiangyayu
Copy link
Author

jiangyayu commented Jun 14, 2023

The format result is correct when I use "( " instead of "(", the problem may lies here.

@jiangyayu
Copy link
Author

Are you able to provide more context?

There is no more context.

@nene
Copy link
Collaborator

nene commented Jun 14, 2023

So, I understand the issue is in some sort of Unicode parenthesis character. I don't know what's the role of this character in this language and how it should be treated in SQL, or how the SQL dialect you're using treats it.

To simplify diagnosing the problem, could you rewrite this problematic of SQL of yours with the minimum amount of non-ascii characters.

For context, you haven't mentioned which dialect of SQL are you using. Like MySQL, SQLite, etc?

@nene nene reopened this Jun 14, 2023
@jiangyayu
Copy link
Author

Simplified SQL: select str(str)from db

This is a type of MySQL without character restrictions and the role of character "(" in Chinese is equivalent to character "(" in English.

@nene nene changed the title [FORMATTING] Invalid format Support chinese parenthesis characters in MySQL Jun 14, 2023
@nene nene changed the title Support chinese parenthesis characters in MySQL Support Chinese parenthesis characters in MySQL Jun 14, 2023
@nene
Copy link
Collaborator

nene commented Jun 14, 2023

Thanks for the explanation @jiangyayu.

I'll need to do some research into how this issue impacts (or doesn't impact) other dialects.

It definitely won't be a simple thing to fix.

A few additional questions, to make sure I get things right:

  • if the formatter would replace all these Chinese "(" characters with plain ASCII "(", it probably wouldn't be acceptable, right?
  • If one uses the Chinese open-paren character, is it mandatory to close it also with Chinese close-paren character, or can the Chinese/ASCII variants be used interchangably?

@jiangyayu
Copy link
Author

For the first question, the answer is right. If the input is Chinese "(" characters and the output turn this characters into "(" which means changed the input, so I think it's not acceptable.

In Chinese, open-paren character and close-paren character should be used in pairs. The grammar is incorrect if only use one of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants