I have an SQL query which unfortunately cannot be written as a prepared statement because it has variable column names. Because of this, I have to build my SQL using String formatting.
The language (SQL dialect) I'm using is PostgreSQL, but because I have String.format()
in my queries, IntelliJ complains about syntax errors in my code.
public class Example {
public String getUniqueFeatureCountSqlQuery(String feature, Long sourceUserId) {
//language=PostgreSQL
return String.format("SELECT COUNT(DISTINCT targetUserId), %s FROM userComments GROUP BY %s WHERE userId = %d",
feature, feature, sourceUserId);
}
}
How do I make IntelliJ recognize this string properly? It should know that it is PostgreSQL which is first formatted by String.format()
.
Thanks to @WillHumphreys I found a solution via youtrack.
You have to go the the User Parameters settings under Tools -> Database -> User Parameters, or use the find action command.
Then make these changes.
You may also have to use the argument index string format notation (String.format("SELECT %1s ...", ...)
) for the parameters to be distinguishable when attempting to alt-enter run the query in the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With