Passing value of datatype interval in parametrized query
TLDR: Skip to chapter &quot;Superior query&quot; below.
You didn't disclose the module you are working with, but the problem is obviously one of type casting. Looks like your parameter is passed as typed value, and I assume text or varchar. There is no implicit type cast for text -&gt; interval:


SELECT castsource::regtype, casttarget::regtype, castcontext
FROM   pg_cast
WHERE  casttarget = 'interval'::regtype;


castsource             | casttarget | castcontext
:--------------------- | :--------- | :----------
time without time zone | interval   | i          
interval               | interval   | i          


db&lt;&gt;fiddle here
If my assumptions are correct you should see an error message like:

ERROR:  operator does not exist: interval &lt; text


I am pretty confident your undisclosed module has ways to pass a different data type or an untyped string literal. Postgres does offer this functionality.
You also state:

I also tried $2::interval

This is odd, because an explicit type cast should also work.
Demo


-- interval typed value
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; interval '6 days'; -- works


| ?column? |
| :------- |
| f        |




--untyped string literal
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; '6 days'; -- works


| ?column? |
| :------- |
| f        |




-- text typed value
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; text '6 days'; -- fails!


ERROR:  operator does not exist: interval &lt; text

LINE 2: ... current_timestamp - timestamp '2018-05-04 18:40' &lt; text '6 ...
^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.





-- text typed value, with explicit cast
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; ('6 days'::text::interval); -- works


| ?column? |
| :------- |
| f        |


The same is true for prepared statements:


PREPARE fooplan_typed_interval(interval) AS
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; $1;

EXECUTE fooplan_typed_interval('6 days');


| ?column? |
| :------- |
| f        |




PREPARE fooplan_untyped AS
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; $1;

EXECUTE fooplan_untyped('6 days');


| ?column? |
| :------- |
| f        |




PREPARE fooplan_typed_text(text) AS
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; $1;

EXECUTE fooplan_typed_text('6 days');  -- only this one fails!


ERROR:  operator does not exist: interval &lt; text

LINE 3: ...ELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; $1;
^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.





PREPARE fooplan_typed_text(text) AS
SELECT current_timestamp - timestamp '2018-05-04 18:40' &lt; $1::interval;

EXECUTE fooplan_typed_text('6 days');


| ?column? |
| :------- |
| f        |


db&lt;&gt;fiddle here
Superior query
All this aside, neither of your queries can use an index (not &quot;sargable&quot;).
Use something like this instead!
server_pg_module:query(&quot;select name from new_table
where creation_date &gt; localtimestamp - interval '1 day' * $1&quot;, [6])

You can multiply an interval with integer.
Or if you figure out the problem with passing typed parameters:
server_pg_module:query(&quot;select name from new_table
where creation_date &gt; localtimestamp - $1::interval&quot;, ['6 days'])

Using localtimestamp to point out that the &quot;current time&quot; depends on your current time zone setting with the type timestamp. Details:

How to get the difference in days between 2 timestamps in PostgreSQL
Ignoring time zones altogether in Rails and PostgreSQL