Commit 92ed9294 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Allow floating point constants for "def_arg" numeric arguments.

 Used in the generic "CREATE xxx" parsing.
Do some automatic type conversion for inserts from other columns.
Previous trouble with "resjunk" regression test remains for now.
parent fa838876
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.12 1998/05/09 23:22:15 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.13 1998/07/08 14:04:09 thomas Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -204,8 +204,7 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -204,8 +204,7 @@ Oid param_type(int t); /* used in parse_expr.c */
%type <ival> sub_type %type <ival> sub_type
%type <list> OptCreateAs, CreateAsList %type <list> OptCreateAs, CreateAsList
%type <node> CreateAsElement %type <node> CreateAsElement
%type <value> NumConst %type <value> NumericOnly, FloatOnly, IntegerOnly
%type <value> IntegerOnly
%type <attr> event_object, attr %type <attr> event_object, attr
%type <sortgroupby> groupby %type <sortgroupby> groupby
%type <sortgroupby> sortby %type <sortgroupby> sortby
...@@ -1180,6 +1179,20 @@ OptSeqElem: CACHE IntegerOnly ...@@ -1180,6 +1179,20 @@ OptSeqElem: CACHE IntegerOnly
} }
; ;
NumericOnly: FloatOnly { $$ = $1; }
| IntegerOnly { $$ = $1; }
FloatOnly: FCONST
{
$$ = makeFloat($1);
}
| '-' FCONST
{
$$ = makeFloat($2);
$$->val.dval = - $$->val.dval;
}
;
IntegerOnly: Iconst IntegerOnly: Iconst
{ {
$$ = makeInteger($1); $$ = makeInteger($1);
...@@ -1384,7 +1397,7 @@ def_elem: def_name '=' def_arg ...@@ -1384,7 +1397,7 @@ def_elem: def_name '=' def_arg
def_arg: ColId { $$ = (Node *)makeString($1); } def_arg: ColId { $$ = (Node *)makeString($1); }
| all_Op { $$ = (Node *)makeString($1); } | all_Op { $$ = (Node *)makeString($1); }
| NumConst { $$ = (Node *)$1; /* already a Value */ } | NumericOnly { $$ = (Node *)$1; }
| Sconst { $$ = (Node *)makeString($1); } | Sconst { $$ = (Node *)makeString($1); }
| SETOF ColId | SETOF ColId
{ {
...@@ -4442,10 +4455,6 @@ ParamNo: PARAM ...@@ -4442,10 +4455,6 @@ ParamNo: PARAM
} }
; ;
NumConst: Iconst { $$ = makeInteger($1); }
| FCONST { $$ = makeFloat($1); }
;
Iconst: ICONST { $$ = $1; }; Iconst: ICONST { $$ = $1; };
Sconst: SCONST { $$ = $1; }; Sconst: SCONST { $$ = $1; };
UserId: IDENT { $$ = $1; }; UserId: IDENT { $$ = $1; };
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.18 1998/06/05 03:49:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.19 1998/07/08 14:04:10 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -198,29 +198,31 @@ find_targetlist_entry(ParseState *pstate, SortGroupBy *sortgroupby, List *tlist) ...@@ -198,29 +198,31 @@ find_targetlist_entry(ParseState *pstate, SortGroupBy *sortgroupby, List *tlist)
List *p_target = tlist; List *p_target = tlist;
TargetEntry *tent = makeNode(TargetEntry); TargetEntry *tent = makeNode(TargetEntry);
if (sortgroupby->range) { if (sortgroupby->range) {
Attr *missingTarget = (Attr *)makeNode(Attr); Attr *missingAttr = (Attr *)makeNode(Attr);
missingTarget->type = T_Attr; missingAttr->type = T_Attr;
missingTarget->relname = palloc(strlen(sortgroupby->range) + 1); missingAttr->relname = palloc(strlen(sortgroupby->range) + 1);
strcpy(missingTarget->relname, sortgroupby->range); strcpy(missingAttr->relname, sortgroupby->range);
missingTarget->attrs = lcons(makeString(sortgroupby->name), NIL); missingAttr->attrs = lcons(makeString(sortgroupby->name), NIL);
transformTargetId(pstate, (Node*)missingTarget, tent, sortgroupby->name, TRUE); tent = transformTargetIdent(pstate, (Node *)missingAttr, tent,
&missingAttr->relname, NULL,
missingAttr->relname, TRUE);
} }
else { else {
Ident *missingTarget = (Ident *)makeNode(Ident); Ident *missingIdent = (Ident *)makeNode(Ident);
missingTarget->type = T_Ident; missingIdent->type = T_Ident;
missingTarget->name = palloc(strlen(sortgroupby->name) + 1); missingIdent->name = palloc(strlen(sortgroupby->name) + 1);
strcpy(missingTarget->name, sortgroupby->name); strcpy(missingIdent->name, sortgroupby->name);
transformTargetId(pstate, (Node*)missingTarget, tent, sortgroupby->name, TRUE); tent = transformTargetIdent(pstate, (Node *)missingIdent, tent,
&missingIdent->name, NULL,
missingIdent->name, TRUE);
} }
/* Add to the end of the target list */ /* Add to the end of the target list */
while (lnext(p_target) != NIL) { while (lnext(p_target) != NIL) {
p_target = lnext(p_target); p_target = lnext(p_target);
...@@ -457,7 +459,7 @@ transformUnionClause(List *unionClause, List *targetlist) ...@@ -457,7 +459,7 @@ transformUnionClause(List *unionClause, List *targetlist)
Node *expr; Node *expr;
expr = ((TargetEntry *)lfirst(next_target))->expr; expr = ((TargetEntry *)lfirst(next_target))->expr;
expr = coerce_target_expr(NULL, expr, itype, otype); expr = CoerceTargetExpr(NULL, expr, itype, otype);
if (expr == NULL) if (expr == NULL)
{ {
elog(ERROR,"Unable to transform %s to %s" elog(ERROR,"Unable to transform %s to %s"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.2 1998/05/29 14:00:20 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.3 1998/07/08 14:04:10 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -273,6 +273,7 @@ TypeCategory(Oid inType) ...@@ -273,6 +273,7 @@ TypeCategory(Oid inType)
case (INT2OID): case (INT2OID):
case (INT4OID): case (INT4OID):
case (INT8OID):
case (FLOAT4OID): case (FLOAT4OID):
case (FLOAT8OID): case (FLOAT8OID):
case (CASHOID): case (CASHOID):
...@@ -387,6 +388,7 @@ PromoteTypeToNext(Oid inType) ...@@ -387,6 +388,7 @@ PromoteTypeToNext(Oid inType)
break; break;
case (INT4OID): case (INT4OID):
case (INT8OID):
case (FLOAT4OID): case (FLOAT4OID):
result = FLOAT8OID; result = FLOAT8OID;
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.30 1998/06/15 19:28:54 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.31 1998/07/08 14:04:10 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -312,6 +312,10 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) ...@@ -312,6 +312,10 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
case T_Expr: case T_Expr:
case T_Var: case T_Var:
case T_Const: case T_Const:
/* T_Param comes from implicit function calls in INSERT/VALUE statements.
* - thomas 1998-06-11
*/
case T_Param:
{ {
result = (Node *) expr; result = (Node *) expr;
break; break;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.19 1998/06/15 19:28:55 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.20 1998/07/08 14:04:10 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -153,7 +153,6 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs, ...@@ -153,7 +153,6 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
Oid *true_oid_array; Oid *true_oid_array;
Node *retval; Node *retval;
bool retset; bool retset;
bool exists;
bool attisset = false; bool attisset = false;
Oid toid = (Oid) 0; Oid toid = (Oid) 0;
Expr *expr; Expr *expr;
...@@ -370,16 +369,18 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs, ...@@ -370,16 +369,18 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs,
rettype = toid; rettype = toid;
retset = true; retset = true;
true_oid_array = oid_array; true_oid_array = oid_array;
exists = true;
} }
else else
{ {
bool exists;
exists = func_get_detail(funcname, nargs, oid_array, &funcid, exists = func_get_detail(funcname, nargs, oid_array, &funcid,
&rettype, &retset, &true_oid_array); &rettype, &retset, &true_oid_array);
}
if (!exists) if (!exists)
elog(ERROR, "No such attribute or function '%s'", funcname); elog(ERROR, "No such function '%s' with the specified attributes",
funcname);
}
/* got it */ /* got it */
funcnode = makeNode(Func); funcnode = makeNode(Func);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.11 1998/02/26 04:33:34 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.12 1998/07/08 14:04:11 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parse_coerce.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
...@@ -371,9 +372,8 @@ attnumTypeId(Relation rd, int attid) ...@@ -371,9 +372,8 @@ attnumTypeId(Relation rd, int attid)
return (rd->rd_att->attrs[attid - 1]->atttypid); return (rd->rd_att->attrs[attid - 1]->atttypid);
} }
/* /* handleTargetColname()
* handleTargetColname - * Use column names from insert.
* use column names from insert
*/ */
void void
handleTargetColname(ParseState *pstate, char **resname, handleTargetColname(ParseState *pstate, char **resname,
...@@ -395,9 +395,8 @@ handleTargetColname(ParseState *pstate, char **resname, ...@@ -395,9 +395,8 @@ handleTargetColname(ParseState *pstate, char **resname,
checkTargetTypes(pstate, *resname, refname, colname); checkTargetTypes(pstate, *resname, refname, colname);
} }
/* /* checkTargetTypes()
* checkTargetTypes - * Checks value and target column types.
* checks value and target column types
*/ */
static void static void
checkTargetTypes(ParseState *pstate, char *target_colname, checkTargetTypes(ParseState *pstate, char *target_colname,
...@@ -432,6 +431,27 @@ checkTargetTypes(ParseState *pstate, char *target_colname, ...@@ -432,6 +431,27 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
resdomno_target = attnameAttNum(pstate->p_target_relation, target_colname); resdomno_target = attnameAttNum(pstate->p_target_relation, target_colname);
attrtype_target = attnumTypeId(pstate->p_target_relation, resdomno_target); attrtype_target = attnumTypeId(pstate->p_target_relation, resdomno_target);
#if FALSE
if ((attrtype_id != attrtype_target)
|| (get_atttypmod(rte->relid, resdomno_id) !=
get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target)))
{
if (can_coerce_type(1, &attrtype_id, &attrtype_target))
{
Node *expr = coerce_type(pstate, expr, attrtype_id, attrtype_target);
elog(ERROR, "Type %s(%d) can be coerced to match target column %s(%d)",
colname, get_atttypmod(rte->relid, resdomno_id),
target_colname, get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target));
}
else
{
elog(ERROR, "Type or size of %s(%d) does not match target column %s(%d)",
colname, get_atttypmod(rte->relid, resdomno_id),
target_colname, get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target));
}
}
#else
if (attrtype_id != attrtype_target) if (attrtype_id != attrtype_target)
elog(ERROR, "Type of %s does not match target column %s", elog(ERROR, "Type of %s does not match target column %s",
colname, target_colname); colname, target_colname);
...@@ -446,5 +466,5 @@ checkTargetTypes(ParseState *pstate, char *target_colname, ...@@ -446,5 +466,5 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target)) get_atttypmod(pstate->p_target_relation->rd_id, resdomno_target))
elog(ERROR, "Length of %s is longer than length of target column %s", elog(ERROR, "Length of %s is longer than length of target column %s",
colname, target_colname); colname, target_colname);
#endif
} }
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment