Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

342
Views
BigQuery - wait UDF function with JavaScript code

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);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!