Re: C-language example of using/returning numeric

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: C-language example of using/returning numeric
Date: 2002-09-16 14:57:05
Message-ID: 3D85F141.4090709@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Mike Mascari <mascarm(at)mascari(dot)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(at)mascari(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ian Harding 2002-09-16 15:20:09 RI Trigger Names
Previous Message Tom Lane 2002-09-16 14:53:55 Re: Error compiling tab-complete