Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,8 @@ public <S> Void visit(Alter alter, S context) {
analysis.unresolved("unsupported");
}
}
return null;
// DEFAULT, CHECK and USING expressions are evaluated against the existing rows
return super.visit(alter, context);
}

@Override
Expand Down Expand Up @@ -1477,7 +1478,8 @@ public <S> Void visit(CreateDomain statement, S context) {
public <S> Void visit(AlterDomain statement, S context) {
analysis.claimTopLevel();
analysis.certain(StmtFeature.MODIFIES_SCHEMA);
return null;
// an added CHECK constraint is evaluated against every column of the domain
return super.visit(statement, context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ void repairPartitionMayModifyDataLikeRepairTable() throws JSQLParserException {
assertThat(f.mayModifyData()).isTrue();
}

/**
* PostgreSQL evaluates these expressions against the rows already stored in the table, or in
* the columns of the domain, while the statement runs, so a function called there may write.
*/
@ParameterizedTest
@ValueSource(strings = {"ALTER TABLE t ALTER COLUMN a TYPE int USING purge_audit(a)",
"ALTER TABLE t ADD COLUMN c int DEFAULT purge_audit()",
"ALTER TABLE t ADD CONSTRAINT c CHECK (purge_audit(a) > 0)",
"ALTER DOMAIN d ADD CONSTRAINT c CHECK (purge_audit(VALUE) > 0)"})
void alterExpressionIsChecked(String sql) throws JSQLParserException {
StatementFeatures impure = analyse(sql);
assertThat(impure.modifiesSchema()).isTrue();
assertThat(impure.mayModifyData()).isTrue();
assertThat(impure.getUnresolvedReferences()).containsExactly("purge_audit");

StatementFeatures pure = analyse(sql, "purge_audit");
assertThat(pure.mayModifyData()).isFalse();
assertThat(pure.getUnresolvedReferences()).isEmpty();
}

// ---- the cases a flag union gets wrong --------------------------------------------------

@Test
Expand Down
Loading