Skip to content

Preserve WITH clauses when deparsing VALUES statements - #2732

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/values-with-deparser-20260928
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/values-with-deparser-20260928

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

StatementDeParser drops the CTE from a top-level WITH ... VALUES query. For example, WITH cte(foo) AS (VALUES (42)) VALUES ((SELECT foo FROM cte)) currently renders as VALUES ((SELECT foo FROM cte)), leaving an undefined relation. The original query was executed successfully on PostgreSQL 18.6 during corpus validation.

Reuse the existing WITH-item deparser support for VALUES, preserving the configured select/expression visitors and their context. Keep the existing constructor and add a select-deparser/context path for callers. When VALUES is nested in an expression, let its deparser own the WITH clause so it is emitted exactly once.

Tests cover direct and statement deparsing, multiple/recursive/materialized CTEs, a data-modifying CTE, nested VALUES queries, custom visitor rewriting, callback context, and an unchanged source AST. No grammar changes are required.

Validation: all production sources compiled with Java 17, and all 32 tests passed across ValuesWithDeParserTest, ValuesTest, and DmlSourceExpressionTest using the offline JUnit runner. Manual round trips for the original/nested query forms also passed. Full Gradle/Maven checks remain for CI. Executing the patched output against PostgreSQL has not been repeated because local DB access is blocked.

Signed-off-by: minleejae <mmj9808@gmail.com>
@minleejae
minleejae marked this pull request as ready for review September 28, 2026 09:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant