Tell IntelliJ to *NEVER* align SQL between adjacent lines and use tab indents instead?

Answered

Hi,

I would like to remove all SQL formatting regarding alignment from one line to another (seriously, who does that anyway?!). How can I do that?

I've digged into the Settings/Code Style/SQL options, I've remove all checkboxes stating stuff about alignment, but I keep on getting random (crappy) aligns. Not to mention that these (shitty) alignments are done using spaces while I've checked "Use tabs for indent", so I quickly get tab+space mixes and the IDE (and me btw) seems to be completly lost...

 

Use cases where I don't want alignments (consider 4 dashes = 1 tab since I cannot put tabs in this description):

- The "IN" content is aligned to the opening parenthesis instead of just being indented by 1 tab

- The SELECT columns are space indented when typing

- The WHEN are space indented

- The ON clause and its AND on the next line are both space indented

SELECT
1,
IF(
t.a > 0,
1,
3),
----(CASE
---- WHEN t.b = 1 THEN 1
---- ELSE 2
END)
FROM (
SELECT 1 AS a) AS t
----LEFT JOIN y
---- ON y.col = t.a
---- AND y.col2 = t.a
WHERE x IN (
1,
2,
3);

Expected:

SELECT
----1,
----IF(
--------t.a > 0,
--------1,
--------3),
----(CASE
--------WHEN t.b = 1 THEN 1
--------ELSE 2
----END)
FROM (
--------SELECT 1 AS a) AS t
----LEFT JOIN y
--------ON y.col = t.a
------------AND y.col2 = t.a
WHERE x IN (
----1,
----2,
----3);

How can I do such very simple alignment and tell IntelliJ to stop trying to align stuff by column between different lines?!

 

Thanks

 

Edit: I "almost" get a non-aligned-between-lines stuff if I add some line break before/after parenthesis and then trigger a "reformat code" (so on-typing result and after-reformat result are not the same?!), but I keep a dandling space where an opening parenthesis was used, and this scares out IntelliJ in more complex queries:

SELECT
----1,
----IF(
--------t.a > 0,
--------1,
--------3),
----(CASE
-------- WHEN t.b = 1 THEN 1
-------- ELSE 2
---- END)
FROM (
----SELECT 1 AS a) AS t
----LEFT JOIN y
----ON y.col = t.a
--------AND y.col2 = t.a
WHERE x IN
----(
---- 1,
---- 2,
---- 3);
2 comments

Try with these options disabled:

Settings (Preferences on macOS) | Editor | Code Style | Enable EditorConfig support

Settings (Preferences on macOS) | Editor | Code Style | Indents Detection | Detect and use existing file indents for editing

Settings (Preferences on macOS) | Editor | Code Style | SQL | Wrapping | Keep when reformatting | Line breaks.

Make also sure Settings (Preferences on macOS) | Editor | Code Style | SQL | Tabs and Indents | Use tab character option is enabled.

 

If issue remains, please file it at https://youtrack.jetbrains.com/issues/DBE with a sample file and the CodeStyle scheme exported.

0

I tried, and I got the same kind of weird behavior. It's even weirder because I get random alignments and space/tabs mixes even with "Disable Formatting" checked?!
I will open up a youtrack issue then.

 

Bright side note: Reset project made me found the "DDL file" for data source, which I was looking for since a while. neat good option you've done here! : )

0

Please sign in to leave a comment.