question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: make line separator in CTE query string configurable

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
beikovcommented, Sep 26, 2019

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 to ConfigurationProperties and put that into QueryConfiguration which is accessible through the MainQuery 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 the createCriteriaBuilderFactory() method

0reactions
jwgmeligmeylingcommented, Oct 18, 2019

Hmm, 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 a QueryConfiguration, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found