2003-03-21 02:58:05 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* numeric.h
|
2003-03-21 02:58:05 +01:00
|
|
|
* Definitions for the exact numeric data type of Postgres
|
1998-12-30 20:56:35 +01:00
|
|
|
*
|
2003-03-21 02:58:05 +01:00
|
|
|
* Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
|
1998-12-30 20:56:35 +01:00
|
|
|
*
|
2014-01-07 22:05:30 +01:00
|
|
|
* Copyright (c) 1998-2014, PostgreSQL Global Development Group
|
1998-12-30 20:56:35 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/numeric.h
|
1998-12-30 20:56:35 +01:00
|
|
|
*
|
2003-03-21 02:58:05 +01:00
|
|
|
*-------------------------------------------------------------------------
|
1998-12-30 20:56:35 +01:00
|
|
|
*/
|
|
|
|
#ifndef _PG_NUMERIC_H_
|
|
|
|
#define _PG_NUMERIC_H_
|
|
|
|
|
2006-07-11 15:54:25 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
2002-10-02 21:21:26 +02:00
|
|
|
/*
|
|
|
|
* Hardcoded precision limit - arbitrary, but must be small enough that
|
|
|
|
* dscale values will fit in 14 bits.
|
1998-12-30 20:56:35 +01:00
|
|
|
*/
|
1999-01-05 12:12:11 +01:00
|
|
|
#define NUMERIC_MAX_PRECISION 1000
|
1998-12-30 20:56:35 +01:00
|
|
|
|
2002-10-02 21:21:26 +02:00
|
|
|
/*
|
2000-01-16 00:42:49 +01:00
|
|
|
* Internal limits on the scales chosen for calculation results
|
|
|
|
*/
|
1999-05-25 18:15:34 +02:00
|
|
|
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
|
2002-10-02 21:21:26 +02:00
|
|
|
#define NUMERIC_MIN_DISPLAY_SCALE 0
|
1998-12-30 20:56:35 +01:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
#define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
|
1998-12-30 20:56:35 +01:00
|
|
|
|
2002-10-02 21:21:26 +02:00
|
|
|
/*
|
|
|
|
* For inherently inexact calculations such as division and square root,
|
|
|
|
* we try to get at least this many significant digits; the idea is to
|
|
|
|
* deliver a result no worse than float8 would.
|
|
|
|
*/
|
|
|
|
#define NUMERIC_MIN_SIG_DIGITS 16
|
1998-12-30 20:56:35 +01:00
|
|
|
|
2010-07-30 06:30:23 +02:00
|
|
|
/* The actual contents of Numeric are private to numeric.c */
|
|
|
|
struct NumericData;
|
|
|
|
typedef struct NumericData *Numeric;
|
1998-12-30 20:56:35 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
/*
|
|
|
|
* fmgr interface macros
|
|
|
|
*/
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X))
|
|
|
|
#define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
#define NumericGetDatum(X) PointerGetDatum(X)
|
|
|
|
#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
|
2000-07-17 05:05:41 +02:00
|
|
|
#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2009-08-10 20:29:27 +02:00
|
|
|
/*
|
|
|
|
* Utility functions in numeric.c
|
|
|
|
*/
|
2010-07-30 06:30:23 +02:00
|
|
|
extern bool numeric_is_nan(Numeric num);
|
2011-04-10 17:42:00 +02:00
|
|
|
int32 numeric_maximum_size(int32 typmod);
|
2009-08-10 20:29:27 +02:00
|
|
|
extern char *numeric_out_sci(Numeric num, int scale);
|
Introduce jsonb, a structured format for storing json.
The new format accepts exactly the same data as the json type. However, it is
stored in a format that does not require reparsing the orgiginal text in order
to process it, making it much more suitable for indexing and other operations.
Insignificant whitespace is discarded, and the order of object keys is not
preserved. Neither are duplicate object keys kept - the later value for a given
key is the only one stored.
The new type has all the functions and operators that the json type has,
with the exception of the json generation functions (to_json, json_agg etc.)
and with identical semantics. In addition, there are operator classes for
hash and btree indexing, and two classes for GIN indexing, that have no
equivalent in the json type.
This feature grew out of previous work by Oleg Bartunov and Teodor Sigaev, which
was intended to provide similar facilities to a nested hstore type, but which
in the end proved to have some significant compatibility issues.
Authors: Oleg Bartunov, Teodor Sigaev, Peter Geoghegan and Andrew Dunstan.
Review: Andres Freund
2014-03-23 21:40:19 +01:00
|
|
|
extern char *numeric_normalize(Numeric num);
|
2009-08-10 20:29:27 +02:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* _PG_NUMERIC_H_ */
|