Senior
Task #2 What will be the result in Session #2? Connecting to a database with an empty table t Session #1 --------------------------- psql> BEGIN; -- T1 psql(T1)> INSERT INTO t(id,val) VALUES (1,'a'); -- no COMMIT psql(T1)> COMMIT; --------------------------- Session #2 --------------------------- psql(T2)> SELECT * FROM t; ---------------------------
sobes.tech AI
Answer from AI
In Session #2, the result will be an empty set of rows.
Explanation:
- In Session #1, BEGIN is executed, then INSERT, but COMMIT is called after INSERT.
- However, the condition states "no COMMIT" after INSERT, and then a COMMIT, which is contradictory. If we assume that COMMIT was not called, then the transaction was not committed.
- If the transaction in Session #1 was not committed (COMMIT not executed), then the changes are not visible to other sessions.
Therefore, when executing SELECT * FROM t; in Session #2, the table t will remain empty, as the insert was not committed and is not visible to other sessions.