Delete and Return Deleted Information

We can use the RETURNING clause to return values from the rows that were deleted using a bulk-delete statement!

				
					
yugabyte=# CREATE TABLE some_data (c1 INT, c2 VARCHAR);
CREATE TABLE

yugabyte=# INSERT INTO some_data VALUES (1, 'A'), (2, 'B'), (3, 'C'), (4, 'D');
INSERT 0 4

yugabyte=# SELECT * FROM some_data;
 c1 | c2
----+----
  4 | D
  3 | C
  1 | A
  2 | B
(4 rows)

yugabyte=# DELETE FROM some_data WHERE c1 IN (1, 4) RETURNING c2;
 c2
----
 D
 A
(2 rows)

DELETE 2
				
			

Have Fun!