SQL Code Style - Whitespace after curly brackets



we are using the default PostgreSQL dialect and the default Code Style for it.

When formatting the following SQL everything is okay:

SELECT colA FROM tab_a

However, when formatting the following SQL we get an unwanted whitespace introduced. We use the curly brackets to insert and replace strings, but woudl like to use the Code Style formatter by DataGrip.

SELECT colA FROM {tab}_a

SELECT colA FROM {tab} _a -- becomes this after formatting.

Is there an option we can change here?

Thanks so much everyone in advance

Hi Toby Ruby,

If assumed that `{tab}_a` is a full table name with an underscore in it, then this formatting behavior is unusual.

I tried to reformat this piece of code in Build #DB-223.8617.3, but haven't been bale to reproduce it. Therefore, can you please update to 223.8617.3 version and observe this behavior again.

If the issue remains, please let us and we'll have a look.

HI Aleksandr,

we are using Build #PY-223.8617.48, PyCharm 2022.3.2 (Professional Edition), which comes with DataGrip as a bundled plugin.

I can see the change being applied in the Settings preview for Editor > Code Style > SQL > General, as well as when formatting a .sql file.




Hi Toby Ruby,

I was finally able to reproduce this scenario. The problem is that the {} brackets are not conventional to postgres SQL syntax and, thus, are not handled as you would expect them to. We've made a workaround for your specific case. Here's what needs to be done:

1. in File | Settings | Database | Query Execution | User Parameters, add either \{\w\w*} or \{\w+} - both will do

2. Select SQL checkbox only in Languages, hit Apply

Reformatting should eliminate white space and keep the object name consistent.


Hi Aleksandr,

This solution hasn't worked for us. 

A screenshot of the applied settings on our end provided below for your reference. Could you please review?


Hi Suraj Gulabani,

Please try to use \{\w\w*} instead. Should be working fine.


I think I found the issue - \{\w\w*} works for the example in the original post, but we were having trouble with other queries which included more than just letters/numbers/underscores inside the curly brackets, e.g. SELECT * FROM {abcd:table}_a. Since the regex token \w represents only letters, numbers, and underscores, this would not prevent the formatting issue for this query.

This pattern seems to work as long as there is no whitespace inside the curly brackets: \{\S+}

This pattern works regardless of what the curly brackets contain, but I guess this could be considered too broad: \{[^}]+}

Regardless, thanks for your help Aleksandr Molchanov!


@Alexsandr Molchanov, it turns out I was wrong about the “fix” for the issue. However, it is related to user parameters. The truth is, configuring a correct user parameter appears to be what is causing the issue.

You should be able to reproduce this using Generic SQL and the default User Parameter settings with this example:

FROM abc_${efg}_hij

After auto-formatting, I get this:

FROM abc_${efg} _hij

This is because of the default User Parameter ${name} being configured:

If I remove that User Parameter, or if I un-check the “In scripts” option beneath it, the formatting issue no longer occurs.

The thing is, we want to have this {name} pattern configure as a User Parameter (including to replace “In scripts”),  so that when we run the query in the console, it prompts us to replace these parameters.

Thanks for your feedback. We'll need more time to analyze this behavior. We'll get back to you on this.

Hello Toby,

I've reproduced this bug and filed a bug report: DBE-19599. You're welcome to watch/vote for it.



Please sign in to leave a comment.