Skip site navigation (1) Skip section navigation (2)

Re: [SQL] convert text to number or number to text

From: José Soares <jose(at)sferacarta(dot)com>
To: JT Kirkpatrick <jt-kirkpatrick(at)mpsllc(dot)com>
Cc: "'pgsql-sql(at)hub(dot)org'" <pgsql-sql(at)hub(dot)org>
Subject: Re: [SQL] convert text to number or number to text
Date: 1999-04-22 12:24:48
Message-ID: 371F1510.F86C876B@sferacarta.com (view raw or flat)
Thread:
Lists: pgsql-sql
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

Try this:

prova=> create table test(t text, i integer);
CREATE

prova=> insert into test values('123',123);
INSERT 64579 1

prova=> select cast(i as text),cast(t as int)from test;
text|int4
----+----
 123| 123
(1 row)

José

In response to

pgsql-sql by date

Next:From: José SoaresDate: 1999-04-22 12:29:56
Subject: Re: [SQL] convert text to number or number to text
Previous:From: George MogaDate: 1999-04-22 11:33:39
Subject: Re: [SQL] default in ALTER

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group