mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +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:
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.21 2001/10/25 05:49:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.22 2001/11/12 21:04:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -163,6 +163,21 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
|
||||
|
||||
switch (type_oid)
|
||||
{
|
||||
case BITOID:
|
||||
if (with_typemod)
|
||||
buf = psnprintf(5 + MAX_INT32_LEN + 1, "bit(%d)",
|
||||
(int) typemod);
|
||||
else
|
||||
{
|
||||
/*
|
||||
* bit with no typmod is not the same as BIT, which means
|
||||
* BIT(1) per SQL spec. Report it as the quoted typename
|
||||
* so that parser will not assign a bogus typmod.
|
||||
*/
|
||||
buf = pstrdup("\"bit\"");
|
||||
}
|
||||
break;
|
||||
|
||||
case BOOLOID:
|
||||
buf = pstrdup("boolean");
|
||||
break;
|
||||
@@ -172,11 +187,17 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
|
||||
buf = psnprintf(11 + MAX_INT32_LEN + 1, "character(%d)",
|
||||
(int) (typemod - VARHDRSZ));
|
||||
else
|
||||
buf = pstrdup("character");
|
||||
{
|
||||
/*
|
||||
* bpchar with no typmod is not the same as CHARACTER,
|
||||
* which means CHARACTER(1) per SQL spec. Report it as
|
||||
* bpchar so that parser will not assign a bogus typmod.
|
||||
*/
|
||||
buf = pstrdup("bpchar");
|
||||
}
|
||||
break;
|
||||
|
||||
case CHAROID:
|
||||
|
||||
/*
|
||||
* This char type is the single-byte version. You have to
|
||||
* double-quote it to get at it in the parser.
|
||||
@@ -329,14 +350,6 @@ format_type_internal(Oid type_oid, int32 typemod, bool allow_invalid)
|
||||
buf = pstrdup("character varying");
|
||||
break;
|
||||
|
||||
case BITOID:
|
||||
if (with_typemod)
|
||||
buf = psnprintf(5 + MAX_INT32_LEN + 1, "bit(%d)",
|
||||
(int) typemod);
|
||||
else
|
||||
buf = pstrdup("bit");
|
||||
break;
|
||||
|
||||
default:
|
||||
name = NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname);
|
||||
if (strspn(name, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(name)
|
||||
|
||||
Reference in New Issue
Block a user