Re: C-language example of using/returning numeric - Mailing list pgsql-general

From Mike Mascari
Subject Re: C-language example of using/returning numeric
Date
Msg-id 3D85F141.4090709@mascari.com
Whole thread Raw
In response to C-language example of using/returning numeric  (Mike Mascari <mascarm@mascari.com>)
List pgsql-general
Tom Lane wrote:
> Mike Mascari <mascarm@mascari.com> writes:
>
>>Does anyone happen to have a server-side C-language example of
>>using the Version-1 calling conventions with the NUMERIC data
>>type?
>
>
> utils/adt/numeric.c is full of examples --- just add the
> PG_FUNCTION_INFO_V1() macro and you have a perfectly good external
> function.
>

Great. I'll have a look.

>
>>Are there any helper functions available to the C-language
>>server-side developer wrt numeric?
>
>
> They are all in numeric.c ... unfortunately, they're mostly static.
>
> What exactly do you need to do?

Nothing fancy. I had written code which took an
application-specific input mask and generated an int8
representation, similar to TO_NUMBER(). The problem with int8
values is that they are limited to around 18 digits. The code
would take a user-defined input mask and a value such as:

'000-000/0000' and '213-555/5555' and return 2135555555 as a
result. It would also verify that the data supplied matched the
mask. The mask could include: 'L' or 'A' for alphanumeric or
alpha characters as well. If the mask included alpha or
alphanumeric placeholders, the function returned 0.

If the mask was entirely numeric, the user would be allowed to
supply a range of values. By converting the text to a numeric
value, I could perform range checks against quantities. E.g.: A
user orders 100 widgets, is prompted for their serial numbers,
supplies 213-555/5500 and 213-555/5600 as the range, and the
order is validated. Since NUMERIC was limited to 1000 digits, I
was just going to change the code to return a NUMERIC instead of
an int8. I guess I'll just return a TEXT result and CAST the
result as a NUMERIC for the various range checks.

Thanks!

Mike Mascari
mascarm@mascari.com




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Error compiling tab-complete
Next
From: "Ian Harding"
Date:
Subject: RI Trigger Names