convert text to number or number to text
convert text to number or number to text
От:
JT Kirkpatrick <jt-kirkpatrick@mpsllc.com>
Дата:
I'm trying to do an update query that compares an int4 field to a variable which I think contains a string (it was passed in through cgi.pm). can I convert that string to an integer? - it will always be a number passing through. I vaguely remember oracle having a to_number function - does postgres have something similar? jt
Re: [SQL] convert text to number or number to text
От:
José Soares <jose@sferacarta.com>
Дата:
JT Kirkpatrick ha scritto:I'm trying to do an update query that compares an int4 field to a variableTry this:
which I think contains a string (it was passed in through cgi.pm). can I
convert that string to an integer? - it will always be a number passing
through. I vaguely remember oracle having a to_number function - does
postgres have something similar?jt
prova=> create table test(t text, i integer);
CREATEprova=> insert into test values('123',123);
INSERT 64579 1prova=> select cast(i as text),cast(t as int)from test;
text|int4
----+----
123| 123
(1 row)José
Re: [SQL] convert text to number or number to text
От:
José Soares <jose@sferacarta.com>
Дата:
This should work:
select cast('123' as int), cast(123 as text);
José
JT Kirkpatrick ha scritto:
> I'm trying to do an update query that compares an int4 field to a variable
> which I think contains a string (it was passed in through cgi.pm). can I
> convert that string to an integer? - it will always be a number passing
> through. I vaguely remember oracle having a to_number function - does
> postgres have something similar?
>
> jt