I have an addresses table with ZIP code field which has type VARCHAR.
I need to select all addresses form this table using ZIP codes range.
If I used next code:
select * from address where cast(zip as bigint) between 90210 and 90220
I get an error on fields where ZIP code cann’t be cast as bigint.
How I can resolve this issue?
Derive a version of the zip column that is a bigint if the zip value is numeric, and null otherwise, and then test that.
So sth like
To make this query efficient, you can create an index on this expression: