Re: help with conversion functions

From: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: help with conversion functions
Date: 2004-07-27 02:29:38
Message-ID: 77ED2BF75D59D1439F90412CC5B109740F6073AE@ie10-sahara.hiso.honeywell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


Hi,

I am working on PostgreSql version 7.4.1 and I am referring PostgreSql 7.4.2
Documentation.
But TO_NUMERIC(text,text) has 2 parameters....but i want to pass only one
parameter....that is the problem.
In the documentation they not explained it clearly....need help on that.

-----Original Message-----
From: Stephan Szabo [mailto:sszabo(at)megazone(dot)bigpanda(dot)com]
Sent: Monday, July 26, 2004 7:15 PM
To: Pradeepkumar, Pyatalo (IE10)
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] help with conversion functions

On Sun, 25 Jul 2004, Pradeepkumar, Pyatalo (IE10) wrote:

> I have written a function to update values in a table. The table structure
> is as follows:
> CREATE TABLE PointAttributes(AttributeId BIGINT NOT NULL,
> PointId BIGINT NOT NULL,
> StrValue VARCHAR(255),
> NumValue FLOAT);
>
> Based on the attribute datatype, i have to fill up either StrValue(if
> datatype is character) or NumValue(if the datatype is numeric).
>
> My function just updates the above table by providing values. The function
> is as follows:
>
> CREATE OR REPLACE FUNCTION PP_UpdatePointParameter(varchar,varchar,text);
>
> the first 2 parameters specify the attributename and pointname. I am
passing
> the value as text in the 3rd parameter.
> Now if the datatype is character, i have to set the StrValue field of the
> table with text value else if the datatype of the attribute is numeric
then
> i have to convert the text to the suitable numeric type and assign it to
the
> NumValue.
>
> I have problems in doing that.....i have used TO_NUMERIC(text) as
specified
> in the POSTGRESQL DOCUMENTATION. When i execute the function, it says
> function to_numeric("unknown") does not exist. You may need to add
explicit
> type casts.

Where did you find that in the docs and which version docs was that?

I'd have suggested to_number(text, text), but it also depends what you
want to do if someone passes something like '1X1' in for a numeric value.

> And also i am not sure what the return type of my function should. I have
to
> just update the table.

In 7.4, you could make it void I think. Otherwise, I'd suggest an
integer.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Stephan Szabo 2004-07-27 04:49:58 Re: help with conversion functions
Previous Message Tom Lane 2004-07-26 20:27:48 Re: Varchar or integer primary key?