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

为啥生成的SQL 里太多括号呀? #48

Closed
yeongher opened this issue Nov 23, 2020 · 5 comments
Closed

为啥生成的SQL 里太多括号呀? #48

yeongher opened this issue Nov 23, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@yeongher
Copy link
Contributor

我运行了官方的示例,生成的SQL 如下:

SELECT ((((SUM(`T0`.`amount` ) / SUM(`T0`.`quantity` ) )) * 100))
FROM `orders` AS `T0`
WHERE ((`T0`.`quantity` > 30) AND 
       `T0`.`sales_at` BETWEEN '2020-10-10 00:00:00' AND '2020-10-30 23:59:59')
GROUP BY `T0`.`product_id`

表达式里的括号太多了,看不太清。

@catchex catchex added the question Further information is requested label Nov 23, 2020
@catchex
Copy link
Member

catchex commented Nov 23, 2020

因为我是在Java 编译之前替换了代码,在替换时无法确定它的优先级,为了保证Java 原始的优先级,在Java 代码真正执行时,所有的表达式都会增加括号,这样就能保证原始的表达式优先级。

@catchex catchex self-assigned this Nov 24, 2020
@catchex catchex added the enhancement New feature or request label Nov 24, 2020
@catchex
Copy link
Member

catchex commented Nov 24, 2020

我想了一下,应该有方法解决,括号太多,SQL 的友好性也不强。

@catchex catchex added wontfix This will not be worked on and removed question Further information is requested labels Dec 8, 2020
@catchex
Copy link
Member

catchex commented Dec 8, 2020

这块是个问题,但暂时还没想到合适的修复方案,只是影响可读性。

@oliviaour
Copy link

我也有同样的问题:
示例代码:

Column column1 = Expressions.column(dataset1, "name");
Column column2 = Expressions.column(dataset2, "name");

Expressions.paren(column1.plus(column2)).toSql(DatabaseType.MySQL).trim()

输出结果:

(((`test_t0`.`name`  + `alias`.`name` )))

太多了括号了吧?

@catchex
Copy link
Member

catchex commented Dec 14, 2020

找到解决方法了,可以和Java 的代码保持一致

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants