Thread: Howto convert floats to text?

Howto convert floats to text?

From
Martin Leja
Date:
Hi,

there are the following functions to convert types other than text to text:

$bash psql -c "\df" | sed -n '1,2 p; /^text.*convert/ p'

return_type|function          |arguments           |description   
-----------+------------------+--------------------+------------------------
----
text       |datetime_text     |datetime            |convert   
text       |int2_text         |int2                |convert   
text       |int4_text         |int4                |convert   
text       |oid_text          |oid                 |convert   
text       |text              |datetime            |convert   
text       |text              |timespan            |convert   
text       |text              |int4                |convert   
text       |text              |int2                |convert   
text       |text              |oid                 |convert   
text       |timespan_text     |timespan            |convert   


is there realy no function to convert a float to text?

--
Regards, martin@unix-ag.org


Re: [SQL] Howto convert floats to text?

From
José Soares
Date:
Use this PL/pgSQL script to create text(float), varchar(float), char(float):

create function "varchar"(float) returns varchar as
'beginreturn $1;
end;
' language 'plpgsql';

create function bpchar(float) returns bpchar as
'beginreturn $1;
end;
' language 'plpgsql';

create function text(float) returns text as
'beginreturn $1;
end;
' language 'plpgsql';

create function float_text(float) returns text as
'       select text($1);
' language 'sql';


Martin Leja ha scritto:

> Hi,
>
> there are the following functions to convert types other than text to text:
>
> $bash psql -c "\df" | sed -n '1,2 p; /^text.*convert/ p'
>
> return_type|function          |arguments           |description
>
> -----------+------------------+--------------------+------------------------
> ----
> text       |datetime_text     |datetime            |convert
>
> text       |int2_text         |int2                |convert
>
> text       |int4_text         |int4                |convert
>
> text       |oid_text          |oid                 |convert
>
> text       |text              |datetime            |convert
>
> text       |text              |timespan            |convert
>
> text       |text              |int4                |convert
>
> text       |text              |int2                |convert
>
> text       |text              |oid                 |convert
>
> text       |timespan_text     |timespan            |convert
>
>
> is there realy no function to convert a float to text?
>
> --
> Regards, martin@unix-ag.org

--
______________________________________________________________
PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jose'




Re: [SQL] Howto convert floats to text?

From
Martin Leja
Date:
At 14:51 04.06.99 +0200, you wrote:
>Use this PL/pgSQL script to create text(float), varchar(float), char(float):
>create function text(float) returns text as
>'begin
> return $1;
>end;
>' language 'plpgsql';

Thanks for the tip, but if i try the above, i get:
ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
Recognized languages are sql, C, internal and the created procedural
languages.

what is pl/pgsql? I using postgres 6.3.2 (slink/stable debian package), do
i hve to upgrade to a higer version, or is this plpgsql thing to be
installed separately?

--
Regards, martin@unix-ag.org


Re: [SQL] Howto convert floats to text?

From
Herouth Maoz
Date:
At 20:22 +0300 on 04/06/1999, Martin Leja wrote:


>
> Thanks for the tip, but if i try the above, i get:
> ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plpgsql'.
> Recognized languages are sql, C, internal and the created procedural
> languages.
>
> what is pl/pgsql? I using postgres 6.3.2 (slink/stable debian package), do
> i hve to upgrade to a higer version, or is this plpgsql thing to be
> installed separately?

pl/pgsql is new in 6.4. If you are working with 6.3.2, you may define a
function in SQL as follows:

testing=> CREATE FUNCTION text( float8 ) returns text
testing-> AS 'select textin( float8out( $1 ) )'
testing-> LANGUAGE 'sql';

Test this:

testing=> select text( 18.4 ) || ' is the number';
?column?
------------------
18.4 is the number
(1 row)

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma