Indenting options for SQL code formatting

Hi,

The SQL code formatting options are quite comprehensive, however I can't figure out any way to prevent it from indenting JOIN and ON conditions. I like my joins and ons to be on separate lines, however when you do that you get a format like this:

select *
from foo f
  join bar b
    on f.val = b.val

I would prefer it like this:

select *
from foo f
join bar b
on f.val = b.val

But I can't find any way to get the formatter to do this.

Cheers
Tom

7 comments
Comment actions Permalink

There is no separate option for this now. I've created the request in YouTrack. Please vote for https://youtrack.jetbrains.com/issue/DBE-2018 .

0
Comment actions Permalink

I went to vote but appears to already have been done! Awesome.

0
Comment actions Permalink

It looks like there is no option to split where/join/group/order by clauses over multiple lines also? This would also be a useful feature, eg change:

select x, y

from foo f

join bar b

on f.x = b.x and f.y = b.y

where f.z = 1 and b.z = 2

group by x, y

order by x, y

Into:

select

    x,

    y

from foo f

join bar b

on

    f.x = b.x

    and f.y = b.y

where

    f.z = 1

    and b.z = 2

group by

    x,

    y

order by

    x,

    y

Of course, you would probably want separate preferences for each of those types, and have the 'If more than one' as you do for the equivalent select clause items.

0
Comment actions Permalink

There is New line before otion available for select, join expression/condition, where, goup, order, etc clauses in the General tab. Does it work for you?

0
Comment actions Permalink

The new line before option only applies to the whole clause, what I'm asking for is a new line between each item in the respective clauses.

Eg new line before changes this:

select *

from foo where a = 1 and b = 2

into this:

select *

from foo

where a = 1 and b = 2

But what I'm asking for is this:

select *

from foo

where

a = 1

and b = 2

0
Comment actions Permalink

Hi Andrey

I hope you don't mind me adding to your ticket, but my need is very similar and I didn't want to create another.

@Tom / @JetBrains, would it be possible to look into this ticket, please?

https://youtrack.jetbrains.com/issue/DBE-2034

0

Please sign in to leave a comment.