SQL - disable auto-format on FROM sub-clause

Answered

Let's say I have such code

 

SELECT * FROM (

SELECT * FROM xxxxxxx

the moment I type closing bracket it formats the code not to my liking.. I can't find the setting to disable this behaviour

0
10 comments

@Dawid Nawrot,

Could you provide a screenshot of your current result and a desired one?  Also, it would be handy to get a sample DDL.


What dialect do you use?

1
Avatar
Permanently deleted user

This is when I start typing, in order to wrap a query in a outer query

When I type the second parenthesis it will format it to:

But I would like the following:

0

You need to pay attention to `Subquery` and `Where` formatting options. As for `*`, it's impossible to put it on a separate line for now.

Example settings for PostgreSQL dialect:

0
Avatar
Permanently deleted user

Can I disable it completely? I am failing at configuring it to behave like I want. It changes indentation etc. I think it will be easier to completely switch off formatting when I press ")", can I do that?

1

@Dawid Nawrot,

>I am failing at configuring it to behave like I want

Could you specify SQL Dialect you work with and describe your desired behavior?


> easier to completely switch off formatting when I press ")"

You need to set values to Do not change

0
Avatar
Permanently deleted user

Hmm it still didn't work. I set Do not change on PostgreSQL and Generic SQL (just in case).

When I start typing this

SELECT
*
FROM ()

And then if I press enter while being inside the parenthesis I get this, with the cursor being at 5 char (not 4, why?)

SELECT
*
FROM (

)

Whereas I would prefer: 

SELECT
*
FROM (

)

With the cursor being at 4 character, so the regular tab size

1

@Dawid Nawrot,

Could you specify console dialect you work with?

 

SQL Code formatter depends from dialect you work with. Did you try Reformate code action?

0
Avatar
Permanently deleted user

It shows Amazon Redshift but there is no specific code style settings for Redshift, is there?

0

>It shows Amazon Redshift but there is no specific code style settings for Redshift, is there?

You should use PostgreSQL code style for Redshift.

0

It appears that, in intelliJ:

The checkbox for Editor > General > Smart keys > Reformat block on typing '}' applies to both typing } in most languages and ) in all SQL dialects. While that can be turned off to make you happy in SQL, it also affects other languages' autoformatting.
I'm not 100% certain this same checkbox is there in DataGrip, but I presume it is.

1

Please sign in to leave a comment.