3 ms·
TRUNCATE is absolutely transactional. You can rollback a TRUNCATE statement if you run it in a transaction. https://dbfiddle.uk/xkgzxMUU https://dbfiddle.uk/xk
by hans_castorp 3y ago
TRUNCATE is absolutely transactional. You can rollback a TRUNCATE statement if you run it in a transaction.
https://dbfiddle.uk/xkgzxMUU https://dbfiddle.uk/xkgzxMUU
The only difference to other DML statements is, that it will put an exclusive lock on the table. So until the TRUNCATE is committed, no other transaction can read from the table.
- petepete 3y ago> The only difference to other DML statements is Truncate is DDL. It's like dropping and recreating the table in a single operation.
- deleted 3y ago[deleted]
- jaggederest 3y ago> TRUNCATE is not MVCC-safe. After truncation, the table will appear empty to concurrent transactions, if they are using a snapshot taken before the truncation occurred. Sorry, that's what I mean. It's safe in the sense that you can roll it back, but it's not safe in the sense that other concurrent transactions will see the table as empty if they are long-running.