Since a number can be up to 15 digits, you need to cast to a 64-bit (8-byte) integer. Try this:
SELECT * FROM table WHERE myint = mytext::int8
The :: cast operator is historical, but convenient. Postgres also follows standard SQL syntax
myint = cast ( mytext as int8)
If you have literal text that you want to compare with int , cast int to text:
SELECT * FROM table WHERE myint::varchar(255) = mytext
Bohemian Dec 10 '12 at 21:32 2012-12-10 21:32
source share