diff options
| author | Jan Wieck <JanWieck@Yahoo.com> | 1998-12-30 19:56:35 +0000 |
|---|---|---|
| committer | Jan Wieck <JanWieck@Yahoo.com> | 1998-12-30 19:56:35 +0000 |
| commit | 0e9d75c6ac97cfb370313b0aff803f9f464d0758 (patch) | |
| tree | 982c849a6f9fe3b36d0233d95c855cfae62d7d5e /src/include | |
| parent | 6059c5a14131cdb71750838ddd7b2034fe540193 (diff) | |
| download | postgresql-0e9d75c6ac97cfb370313b0aff803f9f464d0758.tar.gz | |
Added NUMERIC data type with many builtin funcitons, operators
and aggregates.
Jan
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/catalog/pg_aggregate.h | 6 | ||||
| -rw-r--r-- | src/include/catalog/pg_operator.h | 18 | ||||
| -rw-r--r-- | src/include/catalog/pg_proc.h | 115 | ||||
| -rw-r--r-- | src/include/catalog/pg_type.h | 7 | ||||
| -rw-r--r-- | src/include/utils/builtins.h | 44 | ||||
| -rw-r--r-- | src/include/utils/numeric.h | 67 |
6 files changed, 252 insertions, 5 deletions
diff --git a/src/include/catalog/pg_aggregate.h b/src/include/catalog/pg_aggregate.h index e2f84d636b..7556d2e965 100644 --- a/src/include/catalog/pg_aggregate.h +++ b/src/include/catalog/pg_aggregate.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_aggregate.h,v 1.18 1998/12/08 06:18:11 thomas Exp $ + * $Id: pg_aggregate.h,v 1.19 1998/12/30 19:56:30 wieck Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -95,6 +95,7 @@ DATA(insert OID = 0 ( avg PGUID float4pl float4inc float4div 700 700 700 DATA(insert OID = 0 ( avg PGUID float8pl float8inc float8div 701 701 701 701 _null_ 0.0 )); DATA(insert OID = 0 ( avg PGUID cash_pl float8inc cash_div_flt8 790 790 701 790 _null_ 0.0 )); DATA(insert OID = 0 ( avg PGUID timespan_pl float8inc timespan_div 1186 1186 701 1186 _null_ 0.0 )); +DATA(insert OID = 0 ( avg PGUID numeric_add numeric_inc numeric_div 1700 1700 1700 1700 _null_ 0 )); DATA(insert OID = 0 ( sum PGUID int8pl - - 20 20 0 20 _null_ _null_ )); DATA(insert OID = 0 ( sum PGUID int4pl - - 23 23 0 23 _null_ _null_ )); @@ -103,6 +104,7 @@ DATA(insert OID = 0 ( sum PGUID float4pl - - 700 700 0 700 _null_ _null_ )) DATA(insert OID = 0 ( sum PGUID float8pl - - 701 701 0 701 _null_ _null_ )); DATA(insert OID = 0 ( sum PGUID cash_pl - - 790 790 0 790 _null_ _null_ )); DATA(insert OID = 0 ( sum PGUID timespan_pl - - 1186 1186 0 1186 _null_ _null_ )); +DATA(insert OID = 0 ( sum PGUID numeric_add - - 1700 1700 0 1700 _null_ _null_ )); DATA(insert OID = 0 ( max PGUID int8larger - - 20 20 0 20 _null_ _null_ )); DATA(insert OID = 0 ( max PGUID int4larger - - 23 23 0 23 _null_ _null_ )); @@ -116,6 +118,7 @@ DATA(insert OID = 0 ( max PGUID cashlarger - - 790 790 0 790 _null_ _null_ ) DATA(insert OID = 0 ( max PGUID datetime_larger - - 1184 1184 0 1184 _null_ _null_ )); DATA(insert OID = 0 ( max PGUID timespan_larger - - 1186 1186 0 1186 _null_ _null_ )); DATA(insert OID = 0 ( max PGUID text_larger - - 25 25 0 25 _null_ _null_ )); +DATA(insert OID = 0 ( max PGUID numeric_larger - - 1700 1700 0 1700 _null_ _null_ )); DATA(insert OID = 0 ( min PGUID int8smaller - - 20 20 0 20 _null_ _null_ )); DATA(insert OID = 0 ( min PGUID int4smaller - - 23 23 0 23 _null_ _null_ )); @@ -129,6 +132,7 @@ DATA(insert OID = 0 ( min PGUID cashsmaller - - 790 790 0 790 _null_ _null_ DATA(insert OID = 0 ( min PGUID datetime_smaller - - 1184 1184 0 1184 _null_ _null_ )); DATA(insert OID = 0 ( min PGUID timespan_smaller - - 1186 1186 0 1186 _null_ _null_ )); DATA(insert OID = 0 ( min PGUID text_smaller - - 25 25 0 25 _null_ _null_ )); +DATA(insert OID = 0 ( min PGUID numeric_smaller - - 1700 1700 0 1700 _null_ _null_ )); DATA(insert OID = 0 ( count PGUID - int4inc - 0 0 23 23 _null_ 0 )); diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h index c829419721..8efaed40e1 100644 --- a/src/include/catalog/pg_operator.h +++ b/src/include/catalog/pg_operator.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_operator.h,v 1.47 1998/10/29 18:10:23 thomas Exp $ + * $Id: pg_operator.h,v 1.48 1998/12/30 19:56:31 wieck Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -664,6 +664,22 @@ DATA(insert OID = 827 ( "<<=" PGUID 0 b t f 650 650 16 1004 828 0 0 ne DATA(insert OID = 828 ( ">>" PGUID 0 b t f 650 650 16 826 827 0 0 network_sup intltsel intltjoinsel )); DATA(insert OID = 1004 ( ">>=" PGUID 0 b t f 650 650 16 827 826 0 0 network_supeq intltsel intltjoinsel )); +/* NUMERIC type - OID's 1700-1799 */ +DATA(insert OID = 1752 ( "=" PGUID 0 b t t 1700 1700 16 1752 1753 0 0 numeric_eq eqsel eqjoinsel )); +DATA(insert OID = 1753 ( "<>" PGUID 0 b t f 1700 1700 16 1753 1752 0 0 numeric_ne neqsel neqjoinsel )); +DATA(insert OID = 1754 ( "<" PGUID 0 b t f 1700 1700 16 1756 1757 0 0 numeric_lt intltsel intltjoinsel )); +DATA(insert OID = 1755 ( "<=" PGUID 0 b t f 1700 1700 16 1757 1756 0 0 numeric_le intltsel intltjoinsel )); +DATA(insert OID = 1756 ( ">" PGUID 0 b t f 1700 1700 16 1754 1755 0 0 numeric_gt intltsel intltjoinsel )); +DATA(insert OID = 1757 ( ">=" PGUID 0 b t f 1700 1700 16 1755 1754 0 0 numeric_ge intltsel intltjoinsel )); +DATA(insert OID = 1758 ( "+" PGUID 0 b t f 1700 1700 1700 1758 0 0 0 numeric_add - - )); +DATA(insert OID = 1759 ( "-" PGUID 0 b t f 1700 1700 1700 0 0 0 0 numeric_sub - - )); +DATA(insert OID = 1760 ( "*" PGUID 0 b t f 1700 1700 1700 1760 0 0 0 numeric_mul - - )); +DATA(insert OID = 1761 ( "/" PGUID 0 b t f 1700 1700 1700 0 0 0 0 numeric_div - - )); +DATA(insert OID = 1762 ( "%" PGUID 0 b t f 1700 1700 1700 0 0 0 0 numeric_mod - - )); +DATA(insert OID = 1763 ( "@" PGUID 0 l t f 0 1700 1700 0 0 0 0 numeric_abs - - )); + + + /* * function prototypes */ diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 5a0dc38bc7..f1bfdf15cb 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_proc.h,v 1.86 1998/12/13 23:45:22 thomas Exp $ + * $Id: pg_proc.h,v 1.87 1998/12/30 19:56:32 wieck Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -2168,6 +2168,119 @@ DESCR("host address"); DATA(insert OID = 683 ( network PGUID 14 f t f 1 f 25 "869" 100 0 0 100 "select network_network($1)" - )); DESCR("network address"); +/* OID's 1700 - 1799 NUMERIC data type */ +DATA(insert OID = 1701 ( numeric_in PGUID 11 f t f 1 f 1700 "0" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1702 ( numeric_out PGUID 11 f t f 1 f 23 "0" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1703 ( numeric PGUID 11 f t f 2 f 1700 "1700 23" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1704 ( numeric_abs PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("absolute value"); +DATA(insert OID = 1705 ( abs PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_abs($1)" - )); +DESCR("absolute value"); +DATA(insert OID = 1706 ( numeric_sign PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("sign of value"); +DATA(insert OID = 1707 ( sign PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_sign($1)" - )); +DESCR("sign of value"); +DATA(insert OID = 1708 ( numeric_round PGUID 11 f t f 2 f 1700 "1700 23" 100 0 0 100 foo bar )); +DESCR("value rounded to 'scale'"); +DATA(insert OID = 1709 ( round PGUID 14 f t f 2 f 1700 "1700 23" 100 0 0 100 "select numeric_round($1,$2)" - )); +DESCR("value rounded to 'scale'"); +DATA(insert OID = 1710 ( round PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_round($1,0)" - )); +DESCR("value rounded to 'scale' of zero"); +DATA(insert OID = 1711 ( numeric_trunc PGUID 11 f t f 2 f 1700 "1700 23" 100 0 0 100 foo bar )); +DESCR("value truncated to 'scale'"); +DATA(insert OID = 1712 ( trunc PGUID 14 f t f 2 f 1700 "1700 23" 100 0 0 100 "select numeric_trunc($1,$2)" - )); +DESCR("value truncated to 'scale'"); +DATA(insert OID = 1713 ( trunc PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_trunc($1,0)" - )); +DESCR("value truncated to 'scale' of zero"); +DATA(insert OID = 1714 ( numeric_ceil PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("smallest integer >= value"); +DATA(insert OID = 1715 ( ceil PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_ceil($1)" - )); +DESCR("smallest integer >= value"); +DATA(insert OID = 1716 ( numeric_floor PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("largest integer <= value"); +DATA(insert OID = 1717 ( floor PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_floor($1)" - )); +DESCR("largest integer <= value"); +DATA(insert OID = 1718 ( numeric_eq PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("equal"); +DATA(insert OID = 1719 ( numeric_ne PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("not equal"); +DATA(insert OID = 1720 ( numeric_gt PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("greater-than"); +DATA(insert OID = 1721 ( numeric_ge PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("greater-than-or-equal"); +DATA(insert OID = 1722 ( numeric_lt PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("lower-than"); +DATA(insert OID = 1723 ( numeric_le PGUID 11 f t f 2 f 16 "1700 1700" 100 0 0 100 foo bar )); +DESCR("lower-than-or-equal"); +DATA(insert OID = 1724 ( numeric_add PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("addition"); +DATA(insert OID = 1725 ( numeric_sub PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("subtract"); +DATA(insert OID = 1726 ( numeric_mul PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("multiply"); +DATA(insert OID = 1727 ( numeric_div PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("divide"); +DATA(insert OID = 1728 ( numeric_mod PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("modulus"); +DATA(insert OID = 1729 ( mod PGUID 14 f t f 2 f 1700 "1700 1700" 100 0 0 100 "select numeric_mod($1,$2)" - )); +DESCR("modulus"); +DATA(insert OID = 1730 ( numeric_sqrt PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("square root"); +DATA(insert OID = 1731 ( sqrt PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_sqrt($1)" - )); +DESCR("square root"); +DATA(insert OID = 1732 ( numeric_exp PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("e raised to the power of n"); +DATA(insert OID = 1733 ( exp PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_exp($1)" - )); +DESCR("e raised to the power of n"); +DATA(insert OID = 1734 ( numeric_ln PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("natural logarithm of n"); +DATA(insert OID = 1735 ( ln PGUID 14 f t f 1 f 1700 "1700" 100 0 0 100 "select numeric_ln($1)" - )); +DESCR("natural logarithm of n"); +DATA(insert OID = 1736 ( numeric_log PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("logarithm base m of n"); +DATA(insert OID = 1737 ( log PGUID 14 f t f 2 f 1700 "1700 1700" 100 0 0 100 "select numeric_log($1,$2)" - )); +DESCR("logarithm base m of n"); +DATA(insert OID = 1738 ( numeric_power PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("m raised to the power of n"); +DATA(insert OID = 1739 ( power PGUID 14 f t f 2 f 1700 "1700 1700" 100 0 0 100 "select numeric_power($1,$2)" - )); +DESCR("m raised to the power of n"); +DATA(insert OID = 1740 ( int4_numeric PGUID 11 f t f 1 f 1700 "23" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1741 ( numeric PGUID 14 f t f 1 f 1700 "23" 100 0 0 100 "select int4_numeric($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1742 ( float4_numeric PGUID 11 f t f 1 f 1700 "700" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1743 ( numeric PGUID 14 f t f 1 f 1700 "700" 100 0 0 100 "select float4_numeric($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1744 ( float8_numeric PGUID 11 f t f 1 f 1700 "701" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1745 ( numeric PGUID 14 f t f 1 f 1700 "701" 100 0 0 100 "select float8_numeric($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1746 ( numeric_int4 PGUID 11 f t f 1 f 23 "1700" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1747 ( int4 PGUID 14 f t f 1 f 23 "1700" 100 0 0 100 "select numeric_int4($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1748 ( numeric_float4 PGUID 11 f t f 1 f 700 "1700" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1749 ( float4 PGUID 14 f t f 1 f 700 "1700" 100 0 0 100 "select numeric_float4($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1750 ( numeric_float8 PGUID 11 f t f 1 f 701 "1700" 100 0 0 100 foo bar )); +DESCR("(internal)"); +DATA(insert OID = 1751 ( float8 PGUID 14 f t f 1 f 701 "1700" 100 0 0 100 "select numeric_float8($1)" - )); +DESCR("(internal)"); +DATA(insert OID = 1764 ( numeric_inc PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("increment by one"); +DATA(insert OID = 1765 ( numeric_dec PGUID 11 f t f 1 f 1700 "1700" 100 0 0 100 foo bar )); +DESCR("decrement by one"); +DATA(insert OID = 1766 ( numeric_smaller PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("smaller of two numbers"); +DATA(insert OID = 1767 ( numeric_larger PGUID 11 f t f 2 f 1700 "1700 1700" 100 0 0 100 foo bar )); +DESCR("larger of two numbers"); + + /* * prototypes for functions pg_proc.c */ diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h index 5b0f1e8627..55ff18e331 100644 --- a/src/include/catalog/pg_type.h +++ b/src/include/catalog/pg_type.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_type.h,v 1.52 1998/10/22 13:51:03 momjian Exp $ + * $Id: pg_type.h,v 1.53 1998/12/30 19:56:33 wieck Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -376,6 +376,11 @@ DATA(insert OID = 1296 ( timestamp PGUID 4 19 t b t \054 0 0 timestamp_in time DESCR("limited-range ISO-format date and time"); #define TIMESTAMPOID 1296 +/* OIDS 1700 - 1799 */ +DATA(insert OID = 1700 ( numeric PGUID -1 -1 f b t \054 0 0 numeric_in numeric_out numeric_in numeric_out i _null_ )); +DESCR("arbitrary precision exact numeric data type"); +#define NUMERICOID 1700 + #define VARLENA_FIXED_SIZE(attr) ((attr)->atttypid == BPCHAROID && (attr)->atttypmod > 0) diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index f9ddf18e10..6460fe1a9b 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: builtins.h,v 1.72 1998/12/13 23:36:48 thomas Exp $ + * $Id: builtins.h,v 1.73 1998/12/30 19:56:34 wieck Exp $ * * NOTES * This should normally only be included by fmgr.h. @@ -30,6 +30,7 @@ #include <utils/cash.h> #include <utils/inet.h> #include <utils/rel.h> +#include <utils/numeric.h> /* * Defined in adt/ @@ -560,5 +561,46 @@ bool macaddr_ne(macaddr * a1, macaddr * a2); int4 macaddr_cmp(macaddr * a1, macaddr * a2); text *macaddr_manuf(macaddr * addr); +/* numeric.c */ +Numeric numeric_in(char *str, int dummy, int32 typmod); +char *numeric_out(Numeric num); +Numeric numeric(Numeric num, int32 typmod); +Numeric numeric_abs(Numeric num); +Numeric numeric_sign(Numeric num); +Numeric numeric_round(Numeric num, int32 scale); +Numeric numeric_trunc(Numeric num, int32 scale); +Numeric numeric_ceil(Numeric num); +Numeric numeric_floor(Numeric num); +bool numeric_eq(Numeric num1, Numeric num2); +bool numeric_ne(Numeric num1, Numeric num2); +bool numeric_gt(Numeric num1, Numeric num2); +bool numeric_ge(Numeric num1, Numeric num2); +bool numeric_lt(Numeric num1, Numeric num2); +bool numeric_le(Numeric num1, Numeric num2); +Numeric numeric_add(Numeric num1, Numeric num2); +Numeric numeric_sub(Numeric num1, Numeric num2); +Numeric numeric_mul(Numeric num1, Numeric num2); +Numeric numeric_div(Numeric num1, Numeric num2); +Numeric numeric_mod(Numeric num1, Numeric num2); +Numeric numeric_inc(Numeric num); +Numeric numeric_dec(Numeric num); +Numeric numeric_smaller(Numeric num1, Numeric num2); +Numeric numeric_larger(Numeric num1, Numeric num2); +Numeric numeric_sqrt(Numeric num); +Numeric numeric_exp(Numeric num); +Numeric numeric_ln(Numeric num); +Numeric numeric_log(Numeric num1, Numeric num2); +Numeric numeric_power(Numeric num1, Numeric num2); +Numeric int4_numeric(int32 val); +int32 numeric_int4(Numeric num); +Numeric float4_numeric(float32 val); +float32 numeric_float4(Numeric num); +Numeric float8_numeric(float64 val); +float64 numeric_float8(Numeric num); + #endif /* BUILTINS_H */ + + + + diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h new file mode 100644 index 0000000000..a22c77746d --- /dev/null +++ b/src/include/utils/numeric.h @@ -0,0 +1,67 @@ +/* ---------- + * numeric.h - + * + * Definitions for the exact numeric data type of Postgres + * + * 1998 Jan Wieck + * + * $Header: /cvsroot/pgsql/src/include/utils/numeric.h,v 1.1 1998/12/30 19:56:35 wieck Exp $ + * + * ---------- + */ + +#ifndef _PG_NUMERIC_H_ +#define _PG_NUMERIC_H_ + +#include "postgres.h" + + +/* ---------- + * The hardcoded limits and defaults of the numeric data type + * ---------- + */ +#define NUMERIC_MAX_PRECISION 4000 +#define NUMERIC_DEFAULT_PRECISION 30 +#define NUMERIC_DEFAULT_SCALE 6 + +#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION +#define NUMERIC_MIN_DISPLAY_SCALE NUMERIC_DEFAULT_SCALE + 4 + +#define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION + 4) +#define NUMERIC_MIN_RESULT_SCALE (NUMERIC_DEFAULT_PRECISION + 4) + +#define NUMERIC_UNPACKED_DATASIZE (NUMERIC_MAX_PRECISION * 2 + 4) + + +/* ---------- + * Sign values and macros to deal with n_sign_dscale + * ---------- + */ +#define NUMERIC_SIGN_MASK 0xC000 +#define NUMERIC_POS 0x0000 +#define NUMERIC_NEG 0x4000 +#define NUMERIC_NAN 0xC000 +#define NUMERIC_SIGN(n) ((n)->n_sign_dscale & NUMERIC_SIGN_MASK) +#define NUMERIC_DSCALE(n) ((n)->n_sign_dscale & ~NUMERIC_SIGN_MASK) +#define NUMERIC_IS_NAN(n) (NUMERIC_SIGN(n) != NUMERIC_POS && \ + NUMERIC_SIGN(n) != NUMERIC_NEG) + + +/* ---------- + * The Numeric data type stored in the database + * ---------- + */ +typedef struct NumericData { + int32 varlen; /* Variable size */ + int16 n_weight; /* Weight of 1st digit */ + uint16 n_rscale; /* Result scale */ + uint16 n_sign_dscale; /* Sign + display scale */ + unsigned char n_data[1]; /* Digit data */ +} NumericData; +typedef NumericData *Numeric; + +#define NUMERIC_HDRSZ (sizeof(int32) + sizeof(uint16) * 3) + + +#endif /* _PG_NUMERIC_H_ */ + |
