In Bigquery does not exist a native function like DBMS_LOCK.SLEEP (or DBMS_SESSION.SLEEP) from Oracle ("Puts a procedure to sleep for a specific time"). I tried to use an UDF with JavaScript code but it does not work as I expect: it does not stop other than forced. Can you help me understand what's going on? Thanks!
CREATE TEMP FUNCTION JS_Sleep(x FLOAT64)
RETURNS FLOAT64
LANGUAGE js AS r"""
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
return sleep(x);
""";
select JS_Sleep(10000);
In BigQuery, CURRENT_TIMESTAMP() similar with Date.now() always returns same value in a single statement or in a single transaction as if time stops regardless how many it appears in a query.
In my experience, this also applies to Date.now(). In your case, JS_Sleep() runs forever cause time stops within your query.