1
pg_query_params( SELECT * FROM example WHERE date >= (NOW() - INTERVAL '1 day'), array() );

Above syntax will work, but how can I provide dates dynamically with pg_query_params?

I have tried

pg_query_params( SELECT * FROM example WHERE date >= (NOW() - INTERVAL $1), array('1 day') );
pg_query_params( SELECT * FROM example WHERE date >= (NOW() - INTERVAL $1 day), array('1') );

and several other combinations but they do not seem to work. What is the correct way to do this?

1 Answer 1

1

try this way:

pg_query_params('SELECT * FROM example WHERE date >= (NOW() - $1::interval)', array('1 day') );
Sign up to request clarification or add additional context in comments.

2 Comments

Worked. How did you figure this out?
pure luck - I used to use cast instead defining type before value, like now() - '2016-01-01'::timestamptz instead of now() - timestamptz '2016-01-01' and so on. So I just rewrote your QRY to be cosy with and it worked from first try.

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.