-- cleanup
DROP SEQUENCE IF EXISTS pgbench_deadlock_seq;
DROP TABLE IF EXISTS pgbench_deadlock_data;
DROP PROCEDURE IF EXISTS pgbench_deadlock_wait;
-- hop
CREATE SEQUENCE pgbench_deadlock_seq;
CREATE TABLE pgbench_deadlock_data(
  cid INTEGER PRIMARY KEY,
  myid INTEGER NOT NULL DEFAULT 0
);
INSERT INTO pgbench_deadlock_data(cid) VALUES (1), (2);
CREATE PROCEDURE pgbench_deadlock_wait(id INTEGER) AS $$
DECLARE
  i INTEGER NOT NULL DEFAULT 0;
BEGIN
  -- active wait loop, which relies on the fact that a seq is out of a transaction
  LOOP
    SELECT last_value INTO i FROM pgbench_deadlock_seq;
    EXIT WHEN i >= id;
  END LOOP;
END;
$$ LANGUAGE plpgsql;
-- add statement timeout?
