Increase indentation in WHERE with nested OR clauses
In the case where you have a nested (parenthesized) condition, increase the indention after the new line.
How it currently operates:
SELECT *
FROM MyTable
WHERE
(a=1
OR b=2
OR d=5)
AND c=3
This doesn't really convey the fact that this is a subexpression, and it requires tracing the parenthesis with more complex queries. Something like this would be better:
SELECT *
FROM MyTable
WHERE
(a=1
OR d=5
OR b=2)
AND c=3
So for each parenthesis level with a different logical operator than the previous level (to help prevent over-indenting when parenthesis are applied too liberally), increase the indention level before the next logical operator.
Please have a look at the latest build of SQL Complete.
-
Sheldon commented
Followup post. This is still something that I feel is missing from the nearly perfect code formatting options of SQL Complete. My where statements and on conditions with nested parenthesis statements are not very readable currently without the indentation. I'd love more handling options for parenthesis in logical evaluations (BUT option to NOT affect other functions in select, etc. This is the biggest issue with Apex SQL Formatter. it tries to treat the select the same as the where condition, so simple datediff or other functions can get broken into several lines)
-
Sheldon commented
I also think this could be expanded to just allowing correct alignment with top /bottom of parenthesis. For example, subqueries are still not indented fully. See post I also provided similar to those about subqueries. Both issues are probably related.
-
Sheldon commented
This indentation option would greatly help legibility of the where condition with multiple levels of or's and parenthesis .
-
Esp commented
There should be a section dedicated to how to indent conditions. I'd like to have for example something such as:
(
....a=1
....or b=2
....or d=5
)
and c=3Having more control on conditions would be great.
-
Anthony commented
Ugh, had a feeling that might happen... Here are the examples again, with dashes in place of the tabs.
Current:
SELECT *
FROM MyTable
WHERE
-----(a=1
-----OR b=2
-----OR d=5)
-----AND c=3Requested:
SELECT *
FROM MyTable
WHERE
-----(a=1
----------OR b=2
----------OR d=5)
-----AND c=3