Postgres (cratedb) parameter bug

I have a number input component that I am using as part of query in this way

      and data['localDate']::timestamp between CURRENT_TIMESTAMP - INTERVAL '{{ numberInput1.value }} days' AND CURRENT_TIMESTAMP

When I hover over the numberInput1.value it gives me the correct value (whatever is in the component), however, when executing it, this gives me an error - Cannot cast '$1 days' of type text to type interval

If I just hardcode a number like

      and data['localDate']::timestamp between CURRENT_TIMESTAMP - INTERVAL '5 days' AND CURRENT_TIMESTAMP

then the query works.

I've tried value.toString(), value.toFixed(), but nothing works.

Is there a workaround for this bug?

Thanks!

2 Likes

Hey there @dshoot,

Would this previous solution work out for you?

1 Like

Hi!

I do want to keep the field as number (if possible of course). I restructured the condition to be similar to your but now getting a different error

data['localDate']::timestamp > CURRENT_TIMESTAMP - {{ numberInput1.value + ' days' }}::INTERVAL

gets me

Invalid format: "3 days" is too short

Hi @dshoot,

Totally understand your desire to keep the field as a number. I think that should be possible but worst case you might have to set the value as a string and do some converting just to get things working smoothly.

That new error you have is very odd, I don't think I have seen a 'too short' error before :sweat_smile: could you share a screenshot of this error and the query/resource?