Re: can't cast varchar as integer? - Mailing list pgsql-sql

From David Stanaway
Subject Re: can't cast varchar as integer?
Date
Msg-id 1021412859.992.2468.camel@ciderbox
Whole thread Raw
In response to can't cast varchar as integer?  (Scott Royston <scroyston@mac.com>)
Responses Re: can't cast varchar as integer?
Re: can't cast varchar as integer?
List pgsql-sql
On Tue, 2002-05-14 at 13:56, Scott Royston wrote:
> Mac OSX, postgresql 7.2.1
>
> what's the reasoning behind not being able to cast a varchar as
> integer?  this seems very weird to me:
>
> LEDEV=# create table test (foo varchar(5), bar text);
> LEDEV=# insert into test (foo, bar) values ('123', '123');
> LEDEV=# select cast(foo as integer) from test;
> ERROR:  Cannot cast type 'character varying' to 'integer'
> LEDEV=# select cast(bar as integer) from test;
>   bar
> -----
>   123
> (1 row)


Try this:

scratch=# select foo::text::integer from test;foo
-----123
(1 row)


Or:

scratch=# select int4(foo) from test;int4
------ 123
(1 row)



--
David Stanaway

pgsql-sql by date:

Previous
From: "Joel Burton"
Date:
Subject: Re: can't cast varchar as integer?
Next
From: Oleg Lebedev
Date:
Subject: Re: pg_dumpall