Re: How to convert integer to string in functions

From: David Johnston <polobo(at)yahoo(dot)com>
To: Siva Palanisamy <siva_p(at)hcl(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to convert integer to string in functions
Date: 2011-08-12 14:17:40
Message-ID: CEE8A354-4A76-4271-A932-FB2F996FE997@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> In my table, some of the columns are in text datatype. Few data will come down from UI layer as integers. I want to convert that to string/text before saving it into the table. Please help me on this.
>

SQL Standard: "CAST( value AS text )" [or varchar]
PostgreSQL short-hand: "value::text"

In both formats replace value with whatever you want to convert. When writing a parameterized query (using ?) you can write "?::text" ( or Cast(? AS type) ) to explicitly cast the unknown parameter. The "text" in the above can be any type name.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-08-12 14:29:27 Re: How to convert integer to string in functions
Previous Message Siva Palanisamy 2011-08-12 13:53:57 How to convert integer to string in functions