How to CREATE FUNCTION into PostgreSQL

From: Marcos Cruz <Marcos(dot)Cruz(at)cenpra(dot)gov(dot)br>
To: postgres <pgsql-general(at)postgresql(dot)org>
Subject: How to CREATE FUNCTION into PostgreSQL
Date: 2004-03-16 16:32:51
Message-ID: 200403161332.51200.Marcos.Cruz@cenpra.gov.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I need to create a function to convert a string with a portuguese float-point
representation ( thousand sep = dot, decimal point = comma) to a float8.

When I execute the SQL:
SELECT replace(replace ('1.234.567,08', '.', ''), ',' , '.')::float8 AS test;

the result was the number 1234567.08, which may insert
as a float8 field of a table

When I issue the SQL:
CREATE FUNCTION to_double(text) RETURNS float8 AS
'SELECT (replace(replace(text, '.' , '') , ',' , '.')::float8 AS RESULT
LANGUAGE SQL

it generates an error and function isn't created.

Someone can help me?

Thaks in advance,
Marcos

Responses

Browse pgsql-general by date

  From Date Subject
Next Message BRINER Cedric 2004-03-16 17:09:40 compilation on solaris2.8
Previous Message C G 2004-03-16 16:20:34 Plpython