1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-25 20:23:07 +03:00

Tweak parser so that there is a defined representation for datatypes

bpchar, bit, numeric with typmod -1.  Alter format_type so that this
representation is printed when the typmod is -1.  This ensures that
tables having such columns can be pg_dump'd and reloaded correctly.
Also, remove the rather useless and non-SQL-compliant default
precision and scale for type NUMERIC.  A numeric column declared as
such (with no precision/scale) will now have typmod -1 which means
that numeric values of any precision/scale can be stored in it,
without conversion to a uniform scale.  This seems significantly
more useful than the former behavior.  Part of response to bug #513.
This commit is contained in:
Tom Lane
2001-11-12 21:04:46 +00:00
parent 9c9ea41b3c
commit a585c20d12
4 changed files with 57 additions and 57 deletions

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.211 2001/11/05 17:46:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.212 2001/11/12 21:04:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -34,7 +34,6 @@
#include "rewrite/rewriteManip.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/numeric.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
#include "utils/temprel.h"
@@ -3179,32 +3178,6 @@ transformColumnType(ParseState *pstate, ColumnDef *column)
TypeName *typename = column->typename;
Type ctype = typenameType(typename->name);
/*
* If the column doesn't have an explicitly specified typmod, check to
* see if we want to insert a default length.
*
* Note that we deliberately do NOT look at array or set information
* here; "numeric[]" needs the same default typmod as "numeric".
*/
if (typename->typmod == -1)
{
switch (typeTypeId(ctype))
{
case BPCHAROID:
/* "char" -> "char(1)" */
typename->typmod = VARHDRSZ + 1;
break;
case NUMERICOID:
typename->typmod = VARHDRSZ +
((NUMERIC_DEFAULT_PRECISION << 16) | NUMERIC_DEFAULT_SCALE);
break;
case BITOID:
/* 'bit' -> 'bit(1)' */
typename->typmod = 1;
break;
}
}
/*
* Is this the name of a complex type? If so, implement it as a set.
*

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.273 2001/11/10 22:31:49 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.274 2001/11/12 21:04:45 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -4156,7 +4156,7 @@ opt_numeric: '(' Iconst ',' Iconst ')'
}
| /*EMPTY*/
{
/* Insert "-1" meaning "default"; may be replaced later */
/* Insert "-1" meaning "no limit" */
$$ = -1;
}
;
@@ -4182,7 +4182,7 @@ opt_decimal: '(' Iconst ',' Iconst ')'
}
| /*EMPTY*/
{
/* Insert "-1" meaning "default"; may be replaced later */
/* Insert "-1" meaning "no limit" */
$$ = -1;
}
;
@@ -4208,8 +4208,11 @@ Bit: bit '(' Iconst ')'
{
$$ = makeNode(TypeName);
$$->name = $1;
/* default length, if needed, will be inserted later */
$$->typmod = -1;
/* bit defaults to bit(1), varbit to no limit */
if (strcmp($1, "bit") == 0)
$$->typmod = 1;
else
$$->typmod = -1;
}
;
@@ -4259,8 +4262,11 @@ Character: character '(' Iconst ')' opt_charset
{
$$ = makeNode(TypeName);
$$->name = $1;
/* default length, if needed, will be inserted later */
$$->typmod = -1;
/* char defaults to char(1), varchar to no limit */
if (strcmp($1, "bpchar") == 0)
$$->typmod = VARHDRSZ + 1;
else
$$->typmod = -1;
if (($2 != NULL) && (strcmp($2, "sql_text") != 0)) {
char *type;