diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-20 02:24:50 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-01-20 02:24:50 +0000 |
| commit | 7476e3718b038f563d39ea7f108fbff156275c94 (patch) | |
| tree | a93a49f59461e6d5966bb2e1a666a6bfc1082338 /src/backend/parser/analyze.c | |
| parent | 08195a43f318581e373792fd30e00813ab3ad9fc (diff) | |
| download | postgresql-7476e3718b038f563d39ea7f108fbff156275c94.tar.gz | |
Assign a typmod of -1 to unadorned CHAR and NUMERIC type specs. This
allows casts without specific length requirements to continue to work
as they did before; that is, x::char will not truncate the value of x,
whereas x::char(1) will. Likewise for NUMERIC precision/scale.
The column length defaults of char(1) and numeric(30,6) are now inserted
in analyze.c's processing of CREATE TABLE.
Diffstat (limited to 'src/backend/parser/analyze.c')
| -rw-r--r-- | src/backend/parser/analyze.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 0dd1e9907a..a4c2dd7eff 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: analyze.c,v 1.130 2000/01/16 08:21:59 tgl Exp $ + * $Id: analyze.c,v 1.131 2000/01/20 02:24:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -23,7 +23,11 @@ #include "parser/parse_clause.h" #include "parser/parse_relation.h" #include "parser/parse_target.h" +#include "parser/parse_type.h" #include "utils/builtins.h" +#include "utils/numeric.h" + +void CheckSelectForUpdate(Query *qry); /* no points for style... */ static Query *transformStmt(ParseState *pstate, Node *stmt); static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt); @@ -38,7 +42,7 @@ static Query *transformCreateStmt(ParseState *pstate, CreateStmt *stmt); static void transformForUpdate(Query *qry, List *forUpdate); static void transformFkeyGetPrimaryKey(FkConstraint *fkconstraint); -void CheckSelectForUpdate(Query *qry); +static void transformColumnType(ParseState *pstate, ColumnDef *column); /* kluge to return extra info from transformCreateStmt() */ static List *extras_before; @@ -601,6 +605,8 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt) column = (ColumnDef *) element; columns = lappend(columns, column); + transformColumnType(pstate, column); + /* Special case SERIAL type? */ if (column->is_sequence) { @@ -1701,4 +1707,31 @@ transformFkeyGetPrimaryKey(FkConstraint *fkconstraint) heap_close(pkrel, AccessShareLock); } - +/* + * Special handling of type definition for a column + */ +static void +transformColumnType(ParseState *pstate, ColumnDef *column) +{ + /* + * 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 (column->typename->typmod == -1) + { + switch (typeTypeId(typenameType(column->typename->name))) + { + case BPCHAROID: + /* "char" -> "char(1)" */ + column->typename->typmod = VARHDRSZ + 1; + break; + case NUMERICOID: + column->typename->typmod = VARHDRSZ + + ((NUMERIC_DEFAULT_PRECISION<<16) | NUMERIC_DEFAULT_SCALE); + break; + } + } +} |
