The server stops a statement when it mixes schema-changing commands (DDL) with data-manipulation commands (DML) in a context where that combination is disallowed.
PostgreSQL Error 25007 – schema_and_data_statement_mixing_not_supported occurs when one prepared statement, function, or multi-statement query contains both DDL and DML. Split the DDL and DML into separate statements or run them in different transactions to clear the error.
PostgreSQL Error 25007
PostgreSQL throws error code 25007 when a single SQL unit contains both schema changes and data operations in a context that forbids such mixing. The engine enforces this rule to protect transaction consistency and query plan safety.
You most often meet the error in prepared statements, PL/pgSQL EXECUTE strings, or driver-generated extended queries that concatenate several commands.
Removing the mix or isolating commands resolves the problem quickly.
The server detects a CREATE, ALTER, or DROP clause coexisting with SELECT, INSERT, UPDATE, or DELETE inside one prepared plan.
Because schema state might change partway through execution, PostgreSQL bans the combination to avoid undefined behavior.
PL/pgSQL functions, JDBC prepared statements, and psql’s \; multi-command feature can inadvertently package the conflicting commands together, leading to SQLSTATE 25007 immediately when executed.
First, split schema-changing statements from data-manipulation statements. Execute them sequentially in separate commands or wrap them in distinct transaction blocks.
This guarantees the planner handles each phase with a stable catalog.
When you cannot avoid dynamic SQL, send two EXECUTE calls rather than one long string. In application code, turn off statement preparation for commands containing DDL or issue connection.autocommit = true around pure DDL sections.
Creating a temp table then immediately querying it inside one prepared call triggers 25007.
Send CREATE TEMP TABLE first, then prepare and run the SELECT in a second step.
Altering a table inside a PL/pgSQL function that also reads from that table causes the same error. Move the ALTER TABLE outside the function or place it in a separate DO block run before any reads.
Keep DDL and DML logically separated in code reviews and CI pipelines. Disable automatic statement preparation for DDL-heavy migration scripts.
Use schema-management tools such as Flyway or Liquibase to run migrations independently of application writes.
Adopt Galaxy’s versioned SQL collections to store vetted migration scripts apart from analytic queries, preventing accidental mixes during collaboration.
Error 25001 (active_sql_transaction) surfaces when a command is disallowed inside a transaction block. Fix by moving the command outside BEGIN/COMMIT.
Error 0A000 (feature_not_supported) appears when mixing unsupported features like MOVE WITH HOLD. Verify server version and rewrite the statement.
.
A prepared statement string contains both a CREATE or ALTER and a data-manipulation clause.
Dynamic SQL inside a function concatenates schema changes with data queries.
Applications that create a temp table and immediately SELECT from it without separating the calls.
A PL/pgSQL function tries to ALTER a table and then insert into it before returning.
.
No. It can appear in PL/pgSQL, JDBC batch calls, or any context that ships mixed DDL and DML in one statement.
PostgreSQL does not provide a setting to disable it. You must separate the commands.
Usually not. Catalog changes already force plan invalidation, so separating them adds negligible overhead.
Galaxy’s editor linting flags multi-command strings that mix DDL and DML, and Collections store migrations apart from reporting queries, reducing risk.