Thread: int4 <--> varch2 conversions

int4 <--> varch2 conversions

From
Roland Roberts
Date:
-----BEGIN PGP SIGNED MESSAGE-----

I'm working with a PHP-based application that is using PostgreSQL in
the background.  One of the tables in the application has been used
for double-duty which is causing a problem.  Unfortunately, I can't
readily change the way the table is being used....

One of the columns is defined as being varchar.  But sometimes it
needs to hold an int4 value.  So, I need to be able to convert from
int4 to varchar and back.  The actual query is:

select members.id, members.element, slips.sid, slips.problem
  from slips, members
 where members.element = slips.sid::varchar
   and members.id = 'quickslips'

which give an error in the ::varchar cast.  It also gives an error
without the cast.

I couldn't find any functions in the online manuals that will allow me
to convert back and forth.  Are there any?

This is with PostgreSQL 6.3.2.

roland

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface

iQCVAwUBNl8o2eoW38lmvDvNAQHWDgQAjGWOw/L/OEu75Hw5dSYbm3YXRnbFx6sv
9Wnr0RYnFx795z+7QEEUKjd37iYkgkE9zCCdtOG26T4GqpWjjNju24tngjCba+08
Y15ljI2nTnI1rPIx+eXIYQ110EhcVud87icU4DzuHbzMGn0kHp4TIKICFa2QM055
IjnuITNDax0=
=EEYK
-----END PGP SIGNATURE-----
--
Roland B. Roberts, PhD                  Custom Software Solutions
roberts@panix.com                           101 West 15th St #4NN
                                               New York, NY 10011