Enhancement: make line separator in CTE query string configurable
See original GitHub issueWhen using CTE queries, the produced CTE query string contains line separators. When I enable query logging by enabling hibernate.show_sql
the query spans over multiple log lines. As I am using Logback / Slf4j, each line is prefixed with a timestamp / thread name etc. I therefore can’t easily copy the SQL string (for example to inspect it or run an explain query against it). But it potentially has some side effects for monitoring as well (I haven’t observed such however).
- Is the new added line separator required for some DB dialects?
- If not, can we make this pretty print behaviour configurable?
- If we do, should / could we reuse the
hibernate.format_sql
property (and possibly any Datanucleus equivalent) or should we ship our own property for this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
WITH Queries (Common Table Expressions)
The WITH clause provides a way to use subqueries or perform a data modifying operation in a larger SELECT query. You can also...
Read more >Query optimization techniques in SQL Server: tips and tricks
In this blog post we will show you step by step some tips and tricks for successful Query optimization techniques in SQL Server....
Read more >BigQuery WITH & CTE Statements: Syntax & Usage Simplified ...
This blog talks about BigQuery WITH statements, their syntax, benefits, and tips to write them in great detail.
Read more >WITH common_table_expression (Transact-SQL) - SQL Server
Specifies a temporary named result set, known as a common table expression (CTE). This is derived from a simple query and defined within...
Read more >7.8. WITH Queries (Common Table Expressions) - PostgreSQL
These statements, which are often referred to as Common Table Expressions or CTE s, can be thought of as defining temporary tables that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
How about simply rendering
\n
i.e. add a space before the\n
. Would that help you? We can of course introduce a property to control this. I suggest we add it toConfigurationProperties
and put that intoQueryConfiguration
which is accessible through theMainQuery
object in almost any context. We can parse a few well known properties by doing e.g.if ("true".equals(entityManagerFactory.getProperty("hibernate.format_sql")) { properties.put(ConfigurationProperties.SEPARATE_CTE_WITH_SPACE, true); }
within thecreateCriteriaBuilderFactory()
methodHmm, lots of SQL generation happens within the dialects and
CustomQuerySpecification
(note that I’m mostly talking about the generated SQL and not necessarily the generated JPQL). Both of these classes currently do not have access to aQueryConfiguration
, and for the dialects in particular it will be difficult to pass it on. Perhaps changing the default character used is easier, although it would require a lot of test assertions to be updated as well.