Re: BUG #3506: to_number silently ignore characters - Mailing list pgsql-bugs

From William Leite Araújo
Subject Re: BUG #3506: to_number silently ignore characters
Date
Msg-id bc63ad820708030747p4b112e08la35f0e2bb4794e8@mail.gmail.com
Whole thread Raw
In response to Re: BUG #3506: to_number silently ignore characters  (Laurent Martelli <laurent.martelli@seditel.fr>)
List pgsql-bugs
CREATE OR REPLACE my_to_number(text,text) RETURNS number AS
$$
BEGIN
    IF NOT textregexeq($1,'[0-9]{'||length($2)||'}') THEN
      RAISE EXCEPTION 'TEXT % is not a valid NUMBER',$1;
    END IF;
    RETURNS to_number($1,$2);
 END;
$$ LANGUAGE PLPGSQL IMMUTABLE;

    OR something like ...

2007/8/3, Laurent Martelli < laurent.martelli@seditel.fr>:
Heikki Linnakangas a écrit :
> Laurent Martelli wrote:
>> to_number('123.0','999999') returns 1230, at least on version 7.4 and 8.1. I
>> think it should return 123 or raise an error.
>
> to_number will silently ignore any character that doesn't match the
> pattern. That can be confusing, and not generally a very bright idea in
> applications, but we can't really change the behavior because that could
> break existing applications.

OK. I'm tempted to say that since this is not specified in the
documentation, applications should not rely on this behaviour. But I
understand you will not to break existing applications, so perhaps you
could add a function that would behave in a more expected manner, or at
least document precisely the current behaviour in the documentation.

Best regards,
Laurent


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@postgresql.org so that your
       message can get through to the mailing list cleanly



--
William Leite Araújo
DBA - QUALICONSULT

pgsql-bugs by date:

Previous
From: Rodriguez Fernando
Date:
Subject: Re: Bug Pgsql
Next
From: "Vlad ROMASCANU"
Date:
Subject: Re: BUG #2393: update fails with unique constraint violation