I have a long (and long running, ~30min depending on load) query. It has multiple statements UNION'ed together. Most of the statements are using the GETDATE function[1].

  1. Is the function executed once or multiple times?
  2. If multiple times, would putting it into a WITH statement and then SELECT timestamp FROM <WITH statement> making it getting executed only once?

[1] https://docs.aws.amazon.com/redshift/latest/dg/r_GETDATE.html

  • The overhead of calling getdate() is so small that you shouldn't worry
    – user1822
    Mar 24, 2020 at 6:11
  • It's not the overhead I am concerned about, but whether I am getting the same timestamp in all subqueries or not. The documentation doesn't say anything about it.
    – kev
    Mar 24, 2020 at 10:29


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.