DATA TYPE CONVERTION

Поиск
Список
Период
Сортировка
Искать

DATA TYPE CONVERTION

От:
JORGE MALDONADO <jorgemal1960@gmail.com>
Дата:
Is it possible to convert a numeric value to string within a SELECT query statement?
For example, let's say that I have a table with a numeric field named "quantity". A normal SELECT would be "SELECT quantity FROM tblOrders". What if I want the value returned by the SELECT clause to be of type string instead of decimal?
 
Regards,
Jorge Maldonado

Re: DATA TYPE CONVERTION

От:
Adam Ruth <adamruth@mac.com>
Дата:
You could do:

SELECT quantity::text FROM tblOrders


On 05/05/2009, at 8:21 AM, JORGE MALDONADO wrote:

> Is it possible to convert a numeric value to string within a SELECT  
> query statement?
> For example, let's say that I have a table with a numeric field  
> named "quantity". A normal SELECT would be "SELECT quantity FROM  
> tblOrders". What if I want the value returned by the SELECT clause  
> to be of type string instead of decimal?
>
> Regards,
> Jorge Maldonado

Re: DATA TYPE CONVERTION

От:
Lennin Caro <lennin.caro@yahoo.com>
Дата:

use a cast type


create table test(
	id numeric
);

insert into test values(1);

insert into test values(2);

select id from test;

 id(numeric)
----
  1
  2
(2 rows)

select id::varchar from test;
or
select cast(id as varchar) from test

 id(varchar)
----
  1
  2
(2 rows)

--- On Mon, 5/4/09, JORGE MALDONADO  wrote:

> From: JORGE MALDONADO 
> Subject: [NOVICE] DATA TYPE CONVERTION
> To: pgsql-novice@postgresql.org
> Date: Monday, May 4, 2009, 10:21 PM
> Is it possible to convert a numeric value to string within a
> SELECT query
> statement?
> For example, let's say that I have a table with a
> numeric field named
> "quantity". A normal SELECT would be "SELECT
> quantity FROM tblOrders". What
> if I want the value returned by the SELECT clause to be of
> type string
> instead of decimal?
> 
> Regards,
> Jorge Maldonado


      
FAQ