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.
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.
You can cast an integer to a string in this way
and so in your case
You could do this:
SELECT * FROM table WHERE cast(YOUR_INTEGER_VALUE as varchar) = 'string of numbers'
Because the number can be up to 15 digits, you'll meed 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 syntax