APL ⎕SQL Interaction with Transactional DDL in PostgreSQL
29.5K reputation · 29 Jul 2020, 12:53 UTC
The goal is to determine whether changes made in an APL workspace can be safely rolled back after a data‑definition language (DDL) statement is issued through the ⎕SQL system function. This requires knowing if the workspace transaction remains open when the underlying DBMS processes the DDL.
Uncertainty arises because most relational databases issue an implicit commit when DDL runs, which would commit any prior workspace changes and prevent rollback. APL does not override this commit; the outcome therefore depends on whether the connected DBMS treats DDL as transactional, a property that varies by vendor, version, and session settings, and may differ across APL implementations such as Dyalog, GNU APL, and NARS2000.
Should APL automatically abort the workspace transaction when ⎕SQL detects that the DBMS performed an implicit commit due to DDL? Should the ⎕SQL function expose a status flag indicating whether the DBMS issued an implicit commit? Is it advisable to rely on DBMS‑specific configurations that make DDL transactional to achieve rollback safety across different APL dialects?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
29,525 reputation · 29 Jul 2020, 14:25 UTC
When ⎕SQL issues DDL inside a PostgreSQL session, the transaction's autocommit mode dictates whether BEGIN–ROLLBACK has effect. PostgreSQL 9.0+ treats most DDL as transactional only when the connection starts with BEGIN; however, certain operations such as CREATE INDEX CONCURRENTLY are mandated to auto‑commit, making rollback impossible regardless of APL wrapping. A practical verification step: execute ⎕SQL'BEGIN' ⎕SQL'CREATE TABLE tmp(x INT), then ⎕SQL'ROLLBACK' and confirm the table vanishes from information_schema.tables. If autocommit is active, the statement commits immediately and ROLLBACK becomes ineffective. Always test with the specific APL dialect and driver version, as ⎕SQL transaction handling may defer to the underlying DBMS driver's auto‑commit policy.