Hi,

On Thu, Nov 19, 2026 at 09:51:55AM +0000, Zsolt Parragi wrote:
> Hello
> 
> CREATE TABLE AS EXECUTE only accepts a prepared SELECT, rejecting
> anything else with "prepared statement is not a SELECT". EXPLAIN
> ANALYZE doesn't have the same check, so it runs whatever the prepared
> statement is.
> 
> This is another issue I found while working on EXPLAIN ANALYZE CTAS
> event triggers [1].
> 
> Simple repro:
> 
> CREATE TABLE src (a int);
> PREPARE ins AS INSERT INTO src VALUES (1) RETURNING *;
> CREATE TABLE t1 AS EXECUTE ins; -- ERROR: prepared statement is not a SELECT
> EXPLAIN ANALYZE CREATE TABLE t2 AS EXECUTE ins; -- inserts, creates t2
> with the RETURNING rows
> 
> It seems clearly wrong, and the plain EXPLAIN variant also happily
> shows the plan of something CREATE TABLE AS would reject.
> 
> The attached patch adds the same check to ExplainExecuteQuery. It goes
> back to 9dbf2b7d75d, and the fix is small enough to backpatch.

Agreed, that's an oversight in 9dbf2b7d75d. The fix is pretty straightforward
and looks good to me.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to