zumzum
zumzum

Reputation: 20148

Postgres, query error: ERROR: operator does not exist: character varying = bigint?

I am trying to run this query:

select *
from my_table
where column_one=${myValue}

I get the following error in Datagrip:

[42883] ERROR: operator does not exist: character varying = bigint Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

Now, I have found this question, and I can fix the error by putting a string like this:

select *
from my_table
where column_one='123'

What I need is a way to pass in the '123' as a parameter. I usually do this ${myValue} and it works, but I am not sure how to keep my variable there as an input so I can run dynamic queries in code and let Postgres understand I want to pass in a string and not a number.

Any suggestions?

Here's a screenshot of how I am putting the parameter value in DataGrip...: enter image description here

Ok, so, I just tried to put quotes in the data grip parameters input field for myValue @thirumal's answer things work. I didn't know I have to quote the value for it to work. This is what it looks like:

enter image description here

Upvotes: 1

Views: 2330

Answers (1)

Thirumal
Thirumal

Reputation: 9546

Type cast ${myValue} using SQL Standard,

cast(${myValue} AS varchar)

or using Postgres Syntax:

${myValue}::varchar 

Upvotes: 1

Related Questions