How do I convert an integer to string as part of a PostgreSQL query?
So, for example, I need:
SELECT * FROM table WHERE <some integer> = 'string of numbers'
where <some integer> can be anywhere from 1 to 15 digits long.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the number can be up to 15 digits, you’ll need to cast to an 64 bit (8-byte) integer. Try this:
The
::cast operator is historical but convenient. Postgres also conforms to the SQL standard syntaxIf you have literal text you want to compare with an
int, cast theintto text: