How to use a state variable in a LIKE postgres query

Hi there, I have written the following query

select * from "Pets"
where "Id" like '%{{ petId.value }}%'
and "OwnerId" like '%{{ ownerId.value }}%'

Both petId and ownerId are temporary state variables. The default values for these state variables are just empty strings ("").

When I try to run the query, it gives me the following error.

* error:true
* message:"could not determine data type of parameter $1"
* source:"resource"

Is there something I need to do when trying to use the like query? I feel like theres something about the % character that is throwing the error?

Hey @Tamate and welcome to the forums! Yea, it’s mostly likely related to your syntax. Can you try {{ '%' + petId.value + '%' }}? And same with the second one.

Ahhh thats solved my issue, thank you so much!

@justin in my case if I use this syntax. it will throw a syntax error at or near "$1"



I hope let you come back with solution, it will helpful :person_tipping_hand:

Hey @Keshava_Nanda! Are you trying to set a dynamic column name? This may be a prepared statements issue.

1 Like