Skip to content

fix: validate the query and WITH list of INSERT, UPDATE, DELETE and MERGE - #2937

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:validate-dml-query-and-with-items
Nov 18, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:validate-dml-query-and-with-items

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

InsertValidator validates the source query of an INSERT only when it is a VALUES list. For INSERT ... SELECT it reports Feature.insertFromSelect and stops there, so nothing inside the query reaches SelectValidator or any ValidationCapability. With FeaturesAllowed.INSERT.copy().remove(Feature.function), INSERT INTO t VALUES (pg_read_file('/etc/passwd')) reports function not allowed. but INSERT INTO t SELECT pg_read_file('/etc/passwd') validates with no errors, and INSERT INTO t SELECT a FROM s FOR UPDATE passes FeaturesAllowed.INSERT although selectForUpdate is not part of it. None of the four DML validators look at the WITH list either, so WITH d AS (DELETE FROM s RETURNING a) INSERT INTO t SELECT a FROM d passes FeaturesAllowed.INSERT, the same CTE passes UPDATE and MERGE, and an UPDATE ... RETURNING CTE passes DELETE, while PostgreSQL executes the data-modifying CTE in every one of them. It showed up while checking the DML validators after #2928, which closed the same kind of gap for TABLE and VALUES but did not touch InsertValidator, UpdateValidator, DeleteValidator or MergeValidator. A non-VALUES source query is now walked with SelectValidator the way UpsertValidator already does it, and the WITH items go through a small validateOptionalWithItems helper in AbstractValidator. The new cases in InsertValidatorTest, UpdateValidatorTest, DeleteValidatorTest and MergeValidatorTest fail before and pass after, and PostgresqlVersion.V14 still accepts the statements. Locally ./gradlew test shows the same 35 failures with and without the change (Mockito inline mock maker and file permissions in my sandbox, none of them in validation), and Spotless, Checkstyle, PMD and SpotBugs pass.

@manticore-projects
manticore-projects merged commit ed17b37 into JSQLParser:master Nov 18, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants