converting string value to integer

Started by Ken Guestover 23 years ago3 messagesgeneral
Jump to latest
#1Ken Guest
kguest@stockbyte.com

How do I cast/convert a string value to an integer in 7.1.3?
I've tried using cast but it doesn't seem to work.

k.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________

#2Manfred Koizar
mkoi-pg@aon.at
In reply to: Ken Guest (#1)
Re: converting string value to integer

On Wed, 18 Dec 2002 11:13:50 +0000, Ken Guest <kguest@stockbyte.com>
wrote:

How do I cast/convert a string value to an integer in 7.1.3?
I've tried using cast but it doesn't seem to work.

fred=# SELECT version();
version
--------------------------------------------------------------
PostgreSQL 7.1.3 on i686-pc-cygwin, compiled by GCC 2.95.3-5
(1 row)

fred=# SELECT '123'::INT;
?column?
----------
123
(1 row)

fred=# SELECT CAST('123' AS INT);
?column?
----------
123
(1 row)

Does this answer your question? If not, show us an example of what
you have tried.

Servus
Manfred

#3Ken Guest
kguest@stockbyte.com
In reply to: Manfred Koizar (#2)
Re: converting string value to integer

Manfred Koizar wrote:

On Wed, 18 Dec 2002 11:13:50 +0000, Ken Guest <kguest@stockbyte.com>
wrote:

How do I cast/convert a string value to an integer in 7.1.3?
I've tried using cast but it doesn't seem to work.

<snip>

Does this answer your question? If not, show us an example of what
you have tried.

It does indeed. There were some trailing spaces which I was unaware of,
so I'm now using something akin to
SELECT CAST(TRIM('123 ') AS INT);

which works perfectly.

Thank you Manfred,

ken

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________