Complete the code to start a transaction with read committed isolation level in PostgreSQL.
BEGIN TRANSACTION ISOLATION LEVEL [1];The read committed isolation level ensures that any data read is committed at the moment it is read. This is the default in PostgreSQL.
Complete the SQL query to select data inside a read committed transaction.
BEGIN TRANSACTION ISOLATION LEVEL read committed; SELECT * FROM [1]; COMMIT;The users table is selected here as an example to show data reading inside a read committed transaction.
Fix the error in the transaction isolation level syntax.
BEGIN TRANSACTION ISOLATION [1] read committed;The correct syntax in PostgreSQL is BEGIN TRANSACTION ISOLATION LEVEL read committed;. The keyword between ISOLATION and read committed is LEVEL.
Fill both blanks to create a query that reads only committed data and avoids dirty reads.
SET TRANSACTION ISOLATION LEVEL [1]; SELECT * FROM [2] WHERE status = 'active';
The command SET TRANSACTION ISOLATION LEVEL read committed; sets the isolation level correctly. The users table is used here to select active users.
Fill all three blanks to write a transaction that sets read committed isolation, updates a table, and commits.
BEGIN TRANSACTION ISOLATION LEVEL [1]; UPDATE [2] SET status = 'completed' WHERE id = [3]; COMMIT;
This transaction sets the isolation level to read committed, updates the tasks table setting the status to 'completed' for the task with id 42, and then commits the changes.