I have a postgresql database which look like the following :
+---------------+---------------- ------+------------ ---+
| id (bigint) | name (varying(255)) | price (real) |
+---------------+---------------- ------+------------ ---+
| 1 | name 1 | 0.33 |
+---------------+---------------- ------+------------ ---+
| 1 | name 2 | 1.33 |
+---------------+---------------- ------+------------ ---+
| 1 | name 3 | 1 |
+---------------+---------------- ------+------------ ---+
And then the results of my queries :
SELECT * FROM my_table WHERE price = 1 -- OK (one row returned)
SELECT * FROM my_table WHERE price = 1.0 -- OK (one row returned)
SELECT * FROM my_table WHERE price = 1.33 -- FAIL (no row returned)
SELECT * FROM my_table WHERE price = 0.33 -- FAIL (no row returned)
When the value can't be cast to an non-floating value no lines are returned by postgresql.
I can't figure out why. Have you the same problem ? How can I fix this ?
One solution I see is to use explicit cast to
real
datatype:According to documentation:
Note that: