pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Howto convert floats to text?
4+ messages / 3 participants
[nested] [flat]

* Howto convert floats to text?
@ 1999-06-04 10:45  Martin Leja <martin@unix-ag.org>
  0 siblings, 3 replies; 4+ messages in thread

From: Martin Leja @ 1999-06-04 10:45 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] Howto convert floats to text?
@ 1999-06-04 12:51  José Soares <jose@sferacarta.com>
  parent: Martin Leja <martin@unix-ag.org>
  2 siblings, 0 replies; 4+ messages in thread

From: José Soares @ 1999-06-04 12:51 UTC (permalink / raw)
  To: Martin Leja <martin@unix-ag.org>; +Cc: pgsql-sql

Use this PL/pgSQL script to create text(float), varchar(float), char(float):

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

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

create function text(float) returns text as
'begin
 return $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'





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] Howto convert floats to text?
@ 1999-06-04 17:22  Martin Leja <martin@unix-ag.org>
  parent: Martin Leja <martin@unix-ag.org>
  2 siblings, 0 replies; 4+ messages in thread

From: Martin Leja @ 1999-06-04 17:22 UTC (permalink / raw)
  To: José Soares <jose@sferacarta.com>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] Howto convert floats to text?
@ 1999-06-06 12:26  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: Martin Leja <martin@unix-ag.org>
  2 siblings, 0 replies; 4+ messages in thread

From: Herouth Maoz @ 1999-06-06 12:26 UTC (permalink / raw)
  To: Martin Leja <martin@unix-ag.org>; +Cc: pgsql-sql

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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-06-06 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-06-04 10:45 Howto convert floats to text? Martin Leja <martin@unix-ag.org>
1999-06-04 12:51 ` José Soares <jose@sferacarta.com>
1999-06-04 17:22 ` Martin Leja <martin@unix-ag.org>
1999-06-06 12:26 ` Herouth Maoz <herouth@oumail.openu.ac.il>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox