reset password
Author Message
HelloWorld
Posts: 88
Posted 02:22 Jul 18, 2009 |

ERROR:  operator does not exist: real % integer
LINE 1: ... g.id GROUP BY s.id, s.name) a WHERE a.total_grades % 4 = 0;
                                                               ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

********** Error **********

ERROR: operator does not exist: real % integer
SQL state: 42883
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Character: 227

Above is basically the error that I'm getting for some reason it doesn't recognize it? I switched it to a.total_grades > 1, and it works fine..

cysun
Posts: 2935
Posted 09:15 Jul 18, 2009 |

A floating point number, e.g. 10.1, does not have "Modulus". In other words, the modulus operator can only be applied to two integers, and that's why the error message say "ERROR: operator does not exist: real % integer".

I don't know what your "total_grades" is. If it's the total of grade points, then it is not an integer (e.g. A- is 3.7), and you cannot and should not do a modulus. If it's indeed an integer but is declared as real, you can cast it to an integer (see http://www.postgresql.org/docs/8.3/interactive/sql-expressions.html, Section 4.2.8) and make the modulus work.