1

Here instead of using 7 days interval, I want to use days_gap in a function and pass a numeric value to it instead of a hardcoded value. And then directly call it in the SELECT function

SELECT BOO_NUMBER,
      ROO_NUMBER
    FROM BOO B
    WHERE B.FOO < CURRENT_TIMESTAP - '7 days'::interval

Instead of using '7 days'::interval I want to use a function days_gap which takes a numeric value in the function and can be called respectively instead of 7 days interval.

Please help me with the function code to be called in the select query.

Thanks in advance!

2 Answers 2

1

This should do:

SELECT BOO_NUMBER,
      ROO_NUMBER
    FROM BOO B
    WHERE B.FOO < CURRENT_TIMESTAP - interval '1 day' * days_gap()
Sign up to request clarification or add additional context in comments.

1 Comment

I need a code for days_gap() which takes a number.
0

Are you looking for make_interval()?

SELECT boo_number,
       roo_number
FROM boo b
WHERE b.foo < current_timestap - make_interval(days => 7);

Note that you can always multiply a one day interval with the desired number of days as well:

interval '1 day' * 7 is the same as interval '7 day'

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.