Re: WIP: to_char, support for EEEE format - Mailing list pgsql-hackers

From Brendan Jurd
Subject Re: WIP: to_char, support for EEEE format
Date
Msg-id 37ed240d0904220919h2ab65f87w1822cff9a246881@mail.gmail.com
Whole thread Raw
In response to Re: WIP: to_char, support for EEEE format  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
On Wed, Apr 22, 2009 at 10:13 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> 2009/4/21 Brendan Jurd <direvus@gmail.com>:
>>                numstr = orgnum = (char *) palloc(MAXDOUBLEWIDTH + 1);
>>                if (Num.pre != 1)
>>                        ereport(ERROR,
>>                                        (errcode(ERRCODE_SYNTAX_ERROR),
>>                                         errmsg("invalid using of format EEEE")));
>>
>> Rather than rewording all four copies of the message, I wonder if this
>> test might be better factored out into a separate function?
>
> maybe macro is better - it is too short and without any semantic for
> function, but maybe not. The length of source code is not problem -
> the short function will be inlined, so total length will be same. What
> should be name for this function or for this macro? It hasn't any
> semantic. There should be readable macro only for ereport function -
> some

I was thinking of factoring out the *test*, not just the error message.

If I've been reading this code correctly, the purpose of
               if (Num.pre != 1)

is to make sure that the numeric format has been given with one digit
before the decimal place (so 9.99EEEE would be acceptable but
99.999EEEE would cause the ERROR).

Because this check is made from various places in the code, it makes
sense to me that it should be a function.  Duplicated code makes me
itchy.  Perhaps called something like
sci_notation_check_format(NUMDesc *).

Cheers,
BJ


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Automating Partitions in PostgreSQL - Query on syntax
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #4774: Bug with use execute+xml+xml_encode_special_chars