PGError: ERROR: operator does not exist: boolean ~~* unknown PGError: ERROR: operator does not exist: boolean ~~* unknown sqlite sqlite

PGError: ERROR: operator does not exist: boolean ~~* unknown


Direct answer is near the bottom . . .

This evaluates to

SELECT COUNT(*) FROM "customers" WHERE ((sporty ILIKE '%%') 

Why’s that anyway? Why the '%%'?

In SQL, the '%' is a wildcard. But your problem seems to be that you're building a WHERE clause that has two opening parens, but only one closing paren.

A WHERE clause like this will probably return (or count) all rows:

WHERE (sport ILIKE '%%')

Type casts for SQL queries? How’s that gonna work?

Standard SQL has a CAST() function. Skeleton syntax is

CAST (expression AS type)

So, for example, you can write

CAST (<any timestamp> AS DATE) 

to change a timestamp into a date data type, or

CAST ('32' AS INTEGER)

to change the string '32' to the integer 32.

In my migration the database field looks like this:

t.boolean :sporty

If the column "sporty" is Boolean, this is your real problem. If you try to use a string comparison on a Boolean (which you did: WHERE ((sporty ILIKE '%%') ) you'll get the error message you saw. You want the statement to read more like these:

SELECT COUNT(*) FROM "customers" WHERE sporty;SELECT COUNT(*) FROM "customers" WHERE sporty = true;

or

SELECT COUNT(*) FROM "customers" WHERE NOT sporty;SELECT COUNT(*) FROM "customers" WHERE sporty = false;