Skip to content

support for PREPARE and EXECUTE statement#298

Open
TwistingTwists wants to merge 11 commits intodatafusion-contrib:masterfrom
TwistingTwists:feat/prepare-execute
Open

support for PREPARE and EXECUTE statement#298
TwistingTwists wants to merge 11 commits intodatafusion-contrib:masterfrom
TwistingTwists:feat/prepare-execute

Conversation

@TwistingTwists
Copy link
Copy Markdown
Contributor

@TwistingTwists TwistingTwists commented Feb 24, 2026

Sister PR: sunng87/pgwire#409

Closes: #292

-- Run inside psql connected to datafusion-postgres:
--   psql -h 127.0.0.1 -p 15432

-- 1. Basic PREPARE/EXECUTE
PREPARE my_stmt AS SELECT 42 AS answer;
EXECUTE my_stmt;
EXECUTE my_stmt;

-- 2. Parameterized
PREPARE param_stmt (INT) AS SELECT $1 * 2 AS doubled;
EXECUTE param_stmt(21);
EXECUTE param_stmt(100);

-- 3. DEALLOCATE specific (my_stmt gone, param_stmt still works)
DEALLOCATE my_stmt;
EXECUTE param_stmt(5);

-- 4. DEALLOCATE ALL
PREPARE stmt_a AS SELECT 1;
PREPARE stmt_b AS SELECT 2;
DEALLOCATE ALL;

-- 5. These should all error with "does not exist"
EXECUTE stmt_a;
EXECUTE stmt_b;
EXECUTE param_stmt(1);
EXECUTE never_prepared;

Prepared Statement Test Results

All tests passed end-to-end with real psql.

Test Result
PREPARE my_stmt AS SELECT 42 PREPARE
EXECUTE my_stmt (twice) ✅ Returns 42 both times
PREPARE param_stmt (INT) AS SELECT $1 * 2 PREPARE
EXECUTE param_stmt(21) ✅ Returns 42
EXECUTE param_stmt(100) ✅ Returns 200
DEALLOCATE my_stmt DEALLOCATE
EXECUTE my_stmt after deallocate ✅ Error: "does not exist"
DEALLOCATE ALL DEALLOCATE
EXECUTE stmt_a after DEALLOCATE ALL ✅ Error: "does not exist"

Loading
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.

Add support for PREPARE and EXECUTE statement for simple query

2 participants