I have a table in postgres containing parsed address information. When I run the following query, I get back correct results:
select count(*) from address_table
where (mod(to_number(to_address_left, '99999999'), 2) = 0
and to_address_left <> ' ')
But when I add an OR to it...
select count(*) from address_table
where (mod(to_number(to_address_left, '99999999'), 2) = 0
and to_address_left <> ' ')
or (from_address_left <> ' ')
I get the following error...
ERROR: invalid input syntax for type numeric: " "
SQL state: 22P02
I believe this is an error associated with the TO_NUMBER function. I know there are blank spaces (intentionally) in some of these records, which is why the "and to_address_left <> ' '" is included. But I don't understand why the addition of the OR statement that references a completely different field is causing the otherwise self-contained TO_NUMBER function to generate the error.
This code works fine in Oracle SQL. Why doesn't it work here?