41 static const char *
const small[] = {
42 "zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
43 "eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
44 "fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
45 "thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
47 const char *
const *big = small + 18;
68 if (
value % 10 == 0 && tu > 10)
70 small[
value / 100], big[tu / 10]);
73 small[
value / 100], small[tu]);
76 small[
value / 100], big[tu / 10], small[tu % 10]);
81 if (
value % 10 == 0 && tu > 10)
97 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
98 errmsg(
"money out of range")));
110 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
111 errmsg(
"money out of range")));
123 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
124 errmsg(
"money out of range")));
136 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
137 errmsg(
"money out of range")));
149 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
150 errmsg(
"money out of range")));
160 (
errcode(ERRCODE_DIVISION_BY_ZERO),
161 errmsg(
"division by zero")));
176 Node *escontext = fcinfo->context;
181 bool seen_dot =
false;
201 fpoint = lconvert->frac_digits;
202 if (fpoint < 0 || fpoint > 10)
206 if (*lconvert->mon_decimal_point !=
'\0' &&
207 lconvert->mon_decimal_point[1] ==
'\0')
208 dsymbol = *lconvert->mon_decimal_point;
211 if (*lconvert->mon_thousands_sep !=
'\0')
212 ssymbol = lconvert->mon_thousands_sep;
214 ssymbol = (dsymbol !=
',') ?
"," :
".";
215 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
216 psymbol = (*lconvert->positive_sign !=
'\0') ? lconvert->positive_sign :
"+";
217 nsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
220 printf(
"cashin- precision '%d'; decimal '%c'; thousands '%s'; currency '%s'; positive '%s'; negative '%s'\n",
221 fpoint, dsymbol, ssymbol, csymbol, psymbol, nsymbol);
226 while (isspace((
unsigned char) *s))
228 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
229 s += strlen(csymbol);
230 while (isspace((
unsigned char) *s))
234 printf(
"cashin- string is '%s'\n", s);
240 if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
243 s += strlen(nsymbol);
250 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
251 s += strlen(psymbol);
254 printf(
"cashin- string is '%s'\n", s);
258 while (isspace((
unsigned char) *s))
260 if (strncmp(s, csymbol, strlen(csymbol)) == 0)
261 s += strlen(csymbol);
262 while (isspace((
unsigned char) *s))
266 printf(
"cashin- string is '%s'\n", s);
284 if (isdigit((
unsigned char) *s) && (!seen_dot || dec < fpoint))
286 int8 digit = *s -
'0';
291 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
292 errmsg(
"value \"%s\" is out of range for type %s",
299 else if (*s == dsymbol && !seen_dot)
304 else if (strncmp(s, ssymbol, strlen(ssymbol)) == 0)
305 s += strlen(ssymbol) - 1;
311 if (isdigit((
unsigned char) *s) && *s >=
'5')
316 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
317 errmsg(
"value \"%s\" is out of range for type %s",
322 for (; dec < fpoint; dec++)
326 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
327 errmsg(
"value \"%s\" is out of range for type %s",
335 while (isdigit((
unsigned char) *s))
340 if (isspace((
unsigned char) *s) || *s ==
')')
342 else if (strncmp(s, nsymbol, strlen(nsymbol)) == 0)
345 s += strlen(nsymbol);
347 else if (strncmp(s, psymbol, strlen(psymbol)) == 0)
348 s += strlen(psymbol);
349 else if (strncmp(s, csymbol, strlen(csymbol)) == 0)
350 s += strlen(csymbol);
353 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
354 errmsg(
"invalid input syntax for type %s: \"%s\"",
366 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
367 errmsg(
"value \"%s\" is out of range for type %s",
407 points = lconvert->frac_digits;
408 if (points < 0 || points > 10)
415 mon_group = *lconvert->mon_grouping;
416 if (mon_group <= 0 || mon_group > 6)
420 if (*lconvert->mon_decimal_point !=
'\0' &&
421 lconvert->mon_decimal_point[1] ==
'\0')
422 dsymbol = *lconvert->mon_decimal_point;
425 if (*lconvert->mon_thousands_sep !=
'\0')
426 ssymbol = lconvert->mon_thousands_sep;
428 ssymbol = (dsymbol !=
',') ?
"," :
".";
429 csymbol = (*lconvert->currency_symbol !=
'\0') ? lconvert->currency_symbol :
"$";
434 signsymbol = (*lconvert->negative_sign !=
'\0') ? lconvert->negative_sign :
"-";
435 sign_posn = lconvert->n_sign_posn;
436 cs_precedes = lconvert->n_cs_precedes;
437 sep_by_space = lconvert->n_sep_by_space;
441 signsymbol = lconvert->positive_sign;
442 sign_posn = lconvert->p_sign_posn;
443 cs_precedes = lconvert->p_cs_precedes;
444 sep_by_space = lconvert->p_sep_by_space;
451 bufptr =
buf +
sizeof(
buf) - 1;
463 if (points && digit_pos == 0)
466 *(--bufptr) = dsymbol;
468 else if (digit_pos < 0 && (digit_pos % mon_group) == 0)
471 bufptr -= strlen(ssymbol);
472 memcpy(bufptr, ssymbol, strlen(ssymbol));
475 *(--bufptr) = (uvalue % 10) +
'0';
476 uvalue = uvalue / 10;
478 }
while (uvalue || digit_pos >= 0);
510 (sep_by_space == 1) ?
" " :
"",
515 (sep_by_space == 1) ?
" " :
"",
523 (sep_by_space == 2) ?
" " :
"",
525 (sep_by_space == 1) ?
" " :
"",
530 (sep_by_space == 2) ?
" " :
"",
532 (sep_by_space == 1) ?
" " :
"",
539 (sep_by_space == 1) ?
" " :
"",
541 (sep_by_space == 2) ?
" " :
"",
546 (sep_by_space == 1) ?
" " :
"",
548 (sep_by_space == 2) ?
" " :
"",
555 (sep_by_space == 2) ?
" " :
"",
557 (sep_by_space == 1) ?
" " :
"",
562 (sep_by_space == 1) ?
" " :
"",
564 (sep_by_space == 2) ?
" " :
"",
571 (sep_by_space == 2) ?
" " :
"",
573 (sep_by_space == 1) ?
" " :
"",
578 (sep_by_space == 1) ?
" " :
"",
580 (sep_by_space == 2) ?
" " :
"",
724 (
errcode(ERRCODE_DIVISION_BY_ZERO),
725 errmsg(
"division by zero")));
936 result = (c1 > c2) ? c1 : c2;
951 result = (c1 < c2) ? c1 : c2;
988 dollars =
val / INT64CONST(100);
989 m0 =
val % INT64CONST(100);
990 m1 = (
val / INT64CONST(100)) % 1000;
991 m2 = (
val / INT64CONST(100000)) % 1000;
992 m3 = (
val / INT64CONST(100000000)) % 1000;
993 m4 = (
val / INT64CONST(100000000000)) % 1000;
994 m5 = (
val / INT64CONST(100000000000000)) % 1000;
995 m6 = (
val / INT64CONST(100000000000000000)) % 1000;
1059 fpoint = lconvert->frac_digits;
1060 if (fpoint < 0 || fpoint > 10)
1076 for (
i = 0;
i < fpoint;
i++)
1118 fpoint = lconvert->frac_digits;
1119 if (fpoint < 0 || fpoint > 10)
1124 for (
i = 0;
i < fpoint;
i++)
1151 fpoint = lconvert->frac_digits;
1152 if (fpoint < 0 || fpoint > 10)
1157 for (
i = 0;
i < fpoint;
i++)
1181 fpoint = lconvert->frac_digits;
1182 if (fpoint < 0 || fpoint > 10)
1187 for (
i = 0;
i < fpoint;
i++)
Datum numeric_div(PG_FUNCTION_ARGS)
Datum numeric_round(PG_FUNCTION_ARGS)
Numeric int64_to_numeric(int64 val)
Datum numeric_int8(PG_FUNCTION_ARGS)
Datum numeric_scale(PG_FUNCTION_ARGS)
Datum numeric_mul(PG_FUNCTION_ARGS)
#define FLOAT8_FITS_IN_INT64(num)
Datum int8_cash(PG_FUNCTION_ARGS)
Datum cash_mul_int8(PG_FUNCTION_ARGS)
Datum flt8_mul_cash(PG_FUNCTION_ARGS)
static Cash cash_mi_cash(Cash c1, Cash c2)
Datum cash_mi(PG_FUNCTION_ARGS)
Datum flt4_mul_cash(PG_FUNCTION_ARGS)
Datum cash_numeric(PG_FUNCTION_ARGS)
static Cash cash_div_int64(Cash c, int64 i)
Datum cash_gt(PG_FUNCTION_ARGS)
Datum cash_div_cash(PG_FUNCTION_ARGS)
Datum cash_mul_flt4(PG_FUNCTION_ARGS)
Datum cash_ne(PG_FUNCTION_ARGS)
Datum cash_out(PG_FUNCTION_ARGS)
static Cash cash_mul_int64(Cash c, int64 i)
static Cash cash_mul_float8(Cash c, float8 f)
Datum cash_ge(PG_FUNCTION_ARGS)
Datum cash_div_int4(PG_FUNCTION_ARGS)
Datum cash_in(PG_FUNCTION_ARGS)
Datum numeric_cash(PG_FUNCTION_ARGS)
Datum cash_pl(PG_FUNCTION_ARGS)
Datum cash_eq(PG_FUNCTION_ARGS)
static Cash cash_div_float8(Cash c, float8 f)
Datum cash_div_int2(PG_FUNCTION_ARGS)
static void append_num_word(StringInfo buf, Cash value)
Datum cash_mul_flt8(PG_FUNCTION_ARGS)
Datum int4_mul_cash(PG_FUNCTION_ARGS)
Datum int2_mul_cash(PG_FUNCTION_ARGS)
Datum cash_div_int8(PG_FUNCTION_ARGS)
Datum cash_lt(PG_FUNCTION_ARGS)
Datum cashlarger(PG_FUNCTION_ARGS)
Datum cash_send(PG_FUNCTION_ARGS)
Datum cash_mul_int4(PG_FUNCTION_ARGS)
static Cash cash_pl_cash(Cash c1, Cash c2)
Datum cash_recv(PG_FUNCTION_ARGS)
Datum cash_div_flt8(PG_FUNCTION_ARGS)
Datum cashsmaller(PG_FUNCTION_ARGS)
Datum cash_le(PG_FUNCTION_ARGS)
Datum cash_div_flt4(PG_FUNCTION_ARGS)
Datum int8_mul_cash(PG_FUNCTION_ARGS)
Datum cash_cmp(PG_FUNCTION_ARGS)
Datum cash_mul_int2(PG_FUNCTION_ARGS)
Datum int4_cash(PG_FUNCTION_ARGS)
Datum cash_words(PG_FUNCTION_ARGS)
#define PG_RETURN_CASH(x)
#define PG_GETARG_CASH(n)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
static float8 float8_mul(const float8 val1, const float8 val2)
static float8 float8_div(const float8 val1, const float8 val2)
Datum Int64GetDatum(int64 X)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_GETARG_FLOAT4(n)
#define PG_RETURN_BOOL(x)
#define PG_GETARG_INT16(n)
Datum int8mul(PG_FUNCTION_ARGS)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static uint64 pg_abs_s64(int64 a)
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
if(TABLE==NULL||TABLE_index==NULL)
void pfree(void *pointer)
static Datum NumericGetDatum(Numeric X)
struct lconv * PGLC_localeconv(void)
unsigned char pg_toupper(unsigned char ch)
static int64 DatumGetInt64(Datum X)
static Datum Int32GetDatum(int32 X)
char * psprintf(const char *fmt,...)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
StringInfoData * StringInfo
text * cstring_to_text_with_len(const char *s, int len)