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

New pg_attribute.atttypmod for type-specific information like

varchar length.

Cleans up code so attlen is always length.

Removed varchar() hack added earlier.

Will fix bug in selecting varchar() fields, and varchar() can be
variable length.
This commit is contained in:
Bruce Momjian
1998-01-16 23:21:07 +00:00
parent d7427e4802
commit c65ea0e040
27 changed files with 335 additions and 463 deletions

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.90 1998/01/11 20:01:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.91 1998/01/16 23:20:14 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -2754,7 +2754,7 @@ Character: character '(' Iconst ')'
* between this and "text" is that we blank-pad and
* truncate where necessary
*/
$$->typlen = VARHDRSZ + $3;
$$->typmod = VARHDRSZ + $3;
}
| character
{

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.6 1998/01/05 03:32:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.7 1998/01/16 23:20:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -30,7 +30,7 @@
#include "parser/parse_target.h"
#include "utils/builtins.h"
static Node *parser_typecast(Value *expr, TypeName *typename, int typlen);
static Node *parser_typecast(Value *expr, TypeName *typename, int atttypmod);
/*
* transformExpr -
@ -403,7 +403,7 @@ handleNestedDots(ParseState *pstate, Attr *attr, int *curr_resno, int precedence
}
static Node *
parser_typecast(Value *expr, TypeName *typename, int typlen)
parser_typecast(Value *expr, TypeName *typename, int atttypmod)
{
/* check for passing non-ints */
Const *adt;
@ -492,7 +492,7 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
}
#endif
cp = stringTypeString(tp, const_string, typlen);
cp = stringTypeString(tp, const_string, atttypmod);
if (!typeByVal(tp))
{
@ -540,7 +540,7 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
}
Node *
parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
parser_typecast2(Node *expr, Oid exprType, Type tp, int atttypmod)
{
/* check for passing non-ints */
Const *adt;
@ -627,8 +627,7 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
return ((Node *) adt);
}
cp = stringTypeString(tp, const_string, typlen);
cp = stringTypeString(tp, const_string, atttypmod);
if (!typeByVal(tp))
{

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.6 1998/01/15 20:54:28 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.7 1998/01/16 23:20:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -401,9 +401,9 @@ unary_oper_get_candidates(char *op,
*candidates = NULL;
fmgr_info(NameEqualRegProcedure, (func_ptr *) &opKey[0].sk_func);
fmgr_info(NameEqualRegProcedure, (FmgrInfo *) &opKey[0].sk_func);
opKey[0].sk_argument = NameGetDatum(op);
fmgr_info(CharacterEqualRegProcedure, (func_ptr *) &opKey[1].sk_func);
fmgr_info(CharacterEqualRegProcedure, (FmgrInfo *) &opKey[1].sk_func);
opKey[1].sk_argument = CharGetDatum(rightleft);
/* currently, only "unknown" can be coerced */

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.5 1998/01/05 03:32:30 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.6 1998/01/16 23:20:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -430,10 +430,15 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
elog(ERROR, "Type of %s does not match target column %s",
colname, target_colname);
if ((attrtype_id == BPCHAROID || attrtype_id == VARCHAROID) &&
rd->rd_att->attrs[resdomno_id - 1]->attlen !=
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->attlen)
elog(ERROR, "Length of %s does not match length of target column %s",
if (attrtype_id == BPCHAROID &&
rd->rd_att->attrs[resdomno_id - 1]->atttypmod !=
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->atttypmod)
elog(ERROR, "Length of %s is longer than length of target column %s",
colname, target_colname);
if (attrtype_id == VARCHAROID &&
rd->rd_att->attrs[resdomno_id - 1]->atttypmod >
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->atttypmod)
elog(ERROR, "Length of %s is longer than length of target column %s",
colname, target_colname);
heap_close(rd);

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.5 1998/01/05 03:32:31 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.6 1998/01/16 23:20:22 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -326,7 +326,8 @@ make_targetlist_expr(ParseState *pstate,
Oid type_id,
attrtype;
int type_len,
attrlen;
attrlen,
attrtypmod;
int resdomno;
Relation rd;
bool attrisset;
@ -360,14 +361,8 @@ make_targetlist_expr(ParseState *pstate,
attrtype = attnumTypeId(rd, resdomno);
if ((arrayRef != NIL) && (lfirst(arrayRef) == NIL))
attrtype = GetArrayElementType(attrtype);
if (attrtype == BPCHAROID || attrtype == VARCHAROID)
{
attrlen = rd->rd_att->attrs[resdomno - 1]->attlen;
}
else
{
attrlen = typeLen(typeidType(attrtype));
}
attrlen = typeLen(typeidType(attrtype));
attrtypmod = rd->rd_att->attrs[resdomno - 1]->atttypmod;
#if 0
if (Input_is_string && Typecast_ok)
{
@ -438,13 +433,13 @@ make_targetlist_expr(ParseState *pstate,
expr = (Node *) parser_typecast2(expr,
type_id,
typeidType(typelem),
attrlen);
attrtypmod);
}
else
expr = (Node *) parser_typecast2(expr,
type_id,
typeidType(attrtype),
attrlen);
attrtypmod);
}
else
{

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.3 1998/01/05 03:32:33 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.4 1998/01/16 23:20:23 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -136,15 +136,14 @@ typeTypeFlag(Type t)
/* Given a type structure and a string, returns the internal form of
that string */
char *
stringTypeString(Type tp, char *string, int typlen)
stringTypeString(Type tp, char *string, int atttypmod)
{
Oid op;
Oid typelem;
op = ((TypeTupleForm) GETSTRUCT(tp))->typinput;
typelem = ((TypeTupleForm) GETSTRUCT(tp))->typelem; /* XXX - used for array_in */
/* typlen is for bpcharin() and varcharin() */
return ((char *) fmgr(op, string, typelem, typlen));
return ((char *) fmgr(op, string, typelem, atttypmod));
}
/* Given a type id, returns the out-conversion function of the type */