10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.40 1998/12/18 09:10:32 vadim Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.41 1998/12/30 19:56:28 wieck Exp $
14
14
*
15
15
* HISTORY
16
16
* AUTHOR DATE MAJOR EVENT
46
46
#include "utils/elog.h"
47
47
#include "access/xact.h"
48
48
#include "storage/lmgr.h"
49
+ #include "utils/numeric.h"
49
50
50
51
#ifdef MULTIBYTE
51
52
#include "mb/pg_wchar.h"
@@ -229,7 +230,8 @@ Oid param_type(int t); /* used in parse_expr.c */
229
230
%type <str> generic, numeric, character, datetime
230
231
%type <str> extract_arg
231
232
%type <str> opt_charset, opt_collate
232
- %type <str> opt_float, opt_numeric, opt_decimal
233
+ %type <str> opt_float
234
+ %type <ival> opt_numeric, opt_decimal
233
235
%type <boolean> opt_varying, opt_timezone
234
236
235
237
%type <ival> Iconst
@@ -3018,8 +3020,7 @@ generic: IDENT { $$ = $1; }
3018
3020
3019
3021
/* SQL92 numeric data types
3020
3022
* Check FLOAT() precision limits assuming IEEE floating types.
3021
- * Provide rudimentary DECIMAL() and NUMERIC() implementations
3022
- * by checking parameters and making sure they match what is possible with INTEGER.
3023
+ * Provide real DECIMAL() and NUMERIC() implementations now - Jan 1998-12-30
3023
3024
* - thomas 1997-09-18
3024
3025
*/
3025
3026
Numeric: FLOAT opt_float
@@ -3036,14 +3037,14 @@ Numeric: FLOAT opt_float
3036
3037
| DECIMAL opt_decimal
3037
3038
{
3038
3039
$$ = makeNode(TypeName);
3039
- $$->name = xlateSqlType("integer ");
3040
+ $$->name = xlateSqlType("numeric ");
3040
3041
$$->typmod = -1;
3041
3042
}
3042
3043
| NUMERIC opt_numeric
3043
3044
{
3044
3045
$$ = makeNode(TypeName);
3045
- $$->name = xlateSqlType("integer ");
3046
- $$->typmod = -1 ;
3046
+ $$->name = xlateSqlType("numeric ");
3047
+ $$->typmod = $2 ;
3047
3048
}
3048
3049
;
3049
3050
@@ -3052,7 +3053,7 @@ numeric: FLOAT
3052
3053
| DOUBLE PRECISION
3053
3054
{ $$ = xlateSqlType("float8"); }
3054
3055
| DECIMAL
3055
- { $$ = xlateSqlType("decimal "); }
3056
+ { $$ = xlateSqlType("numeric "); }
3056
3057
| NUMERIC
3057
3058
{ $$ = xlateSqlType("numeric"); }
3058
3059
;
@@ -3076,42 +3077,55 @@ opt_float: '(' Iconst ')'
3076
3077
3077
3078
opt_numeric: '(' Iconst ',' Iconst ')'
3078
3079
{
3079
- if ($2 != 9)
3080
- elog(ERROR,"NUMERIC precision %d must be 9",$2);
3081
- if ($4 != 0)
3082
- elog(ERROR,"NUMERIC scale %d must be zero",$4);
3080
+ if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
3081
+ elog(ERROR,"NUMERIC precision %d must be beween 1 and %d",
3082
+ $2, NUMERIC_MAX_PRECISION);
3083
+ if ($4 < 0 || $4 > $2)
3084
+ elog(ERROR,"NUMERIC scale %d must be between 0 and precision %d",
3085
+ $4,$2);
3086
+
3087
+ $$ = (($2 << 16) | $4) + VARHDRSZ;
3083
3088
}
3084
3089
| '(' Iconst ')'
3085
3090
{
3086
- if ($2 != 9)
3087
- elog(ERROR,"NUMERIC precision %d must be 9",$2);
3091
+ if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
3092
+ elog(ERROR,"NUMERIC precision %d must be beween 1 and %d",
3093
+ $2, NUMERIC_MAX_PRECISION);
3094
+
3095
+ $$ = ($2 << 16) + VARHDRSZ;
3088
3096
}
3089
3097
| /*EMPTY*/
3090
3098
{
3091
- $$ = NULL ;
3099
+ $$ = ((NUMERIC_DEFAULT_PRECISION << 16) | NUMERIC_DEFAULT_SCALE) + VARHDRSZ ;
3092
3100
}
3093
3101
;
3094
3102
3095
3103
opt_decimal: '(' Iconst ',' Iconst ')'
3096
3104
{
3097
- if ($2 > 9)
3098
- elog(ERROR,"DECIMAL precision %d exceeds implementation limit of 9",$2);
3099
- if ($4 != 0)
3100
- elog(ERROR,"DECIMAL scale %d must be zero",$4);
3101
- $$ = NULL;
3105
+ if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
3106
+ elog(ERROR,"DECIMAL precision %d must be beween 1 and %d",
3107
+ $2, NUMERIC_MAX_PRECISION);
3108
+ if ($4 < 0 || $4 > $2)
3109
+ elog(ERROR,"DECIMAL scale %d must be between 0 and precision %d",
3110
+ $4,$2);
3111
+
3112
+ $$ = (($2 << 16) | $4) + VARHDRSZ;
3102
3113
}
3103
3114
| '(' Iconst ')'
3104
3115
{
3105
- if ($2 > 9)
3106
- elog(ERROR,"DECIMAL precision %d exceeds implementation limit of 9",$2);
3107
- $$ = NULL;
3116
+ if ($2 < 1 || $2 > NUMERIC_MAX_PRECISION)
3117
+ elog(ERROR,"DECIMAL precision %d must be beween 1 and %d",
3118
+ $2, NUMERIC_MAX_PRECISION);
3119
+
3120
+ $$ = ($2 << 16) + VARHDRSZ;
3108
3121
}
3109
3122
| /*EMPTY*/
3110
3123
{
3111
- $$ = NULL ;
3124
+ $$ = ((NUMERIC_DEFAULT_PRECISION << 16) | NUMERIC_DEFAULT_SCALE) + VARHDRSZ ;
3112
3125
}
3113
3126
;
3114
3127
3128
+
3115
3129
/* SQL92 character data types
3116
3130
* The following implements CHAR() and VARCHAR().
3117
3131
* We do it here instead of the 'Generic' production
0 commit comments