Skip to content

Commit 3dd23aa

Browse files
committed
Allow functions and operators on internally-identical types to succeed.
1 parent 0ab2921 commit 3dd23aa

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

src/backend/parser/analyze.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.34 1997/08/19 21:32:11 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.35 1997/08/22 00:02:04 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1345,7 +1345,7 @@ make_targetlist_expr(ParseState *pstate,
13451345
} else
13461346
if (attrtype != type_id) {
13471347
if ((attrtype == INT2OID) && (type_id == INT4OID))
1348-
lfirst(expr) = lispInteger (INT2OID);
1348+
lfirst(expr) = lispInteger (INT2OID); do CASHOID too
13491349
else if ((attrtype == FLOAT4OID) && (type_id == FLOAT8OID))
13501350
lfirst(expr) = lispInteger (FLOAT4OID);
13511351
else

src/backend/parser/catalog_utils.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.21 1997/08/19 21:32:12 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.22 1997/08/22 00:02:05 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -373,6 +373,7 @@ equivalentOpersAfterPromotion(CandidateList candidates)
373373
case FLOAT4OID:
374374
case INT4OID:
375375
case INT2OID:
376+
case CASHOID:
376377
c->args[0] = FLOAT8OID;
377378
break;
378379
default:
@@ -383,6 +384,7 @@ equivalentOpersAfterPromotion(CandidateList candidates)
383384
case FLOAT4OID:
384385
case INT4OID:
385386
case INT2OID:
387+
case CASHOID:
386388
c->args[1] = FLOAT8OID;
387389
break;
388390
default:
@@ -570,6 +572,7 @@ unary_oper_get_candidates(char *op,
570572
opKey[1].sk_argument = CharGetDatum(rightleft);
571573

572574
/* currently, only "unknown" can be coerced */
575+
/* but we should allow types that are internally the same to be "coerced" */
573576
if (typeId != UNKNOWNOID) {
574577
return 0;
575578
}
@@ -956,7 +959,14 @@ can_coerce(int nargs, Oid *input_typeids, Oid *func_typeids)
956959
*/
957960
for (i=0; i<nargs; i++) {
958961
if (input_typeids[i] != func_typeids[i]) {
959-
if (input_typeids[i] != UNKNOWNOID || func_typeids[i] == 0)
962+
if ((input_typeids[i] == BPCHAROID && func_typeids[i] == TEXTOID) ||
963+
(input_typeids[i] == BPCHAROID && func_typeids[i] == VARCHAROID) ||
964+
(input_typeids[i] == VARCHAROID && func_typeids[i] == TEXTOID) ||
965+
(input_typeids[i] == VARCHAROID && func_typeids[i] == BPCHAROID) ||
966+
(input_typeids[i] == CASHOID && func_typeids[i] == INT4OID) ||
967+
(input_typeids[i] == INT4OID && func_typeids[i] == CASHOID))
968+
; /* these are OK */
969+
else if (input_typeids[i] != UNKNOWNOID || func_typeids[i] == 0)
960970
return false;
961971

962972
tp = get_id_type(input_typeids[i]);

src/backend/parser/parse_query.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.17 1997/08/19 21:32:16 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.18 1997/08/22 00:02:07 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -378,7 +378,8 @@ make_op(char *opname, Node *ltree, Node *rtree)
378378
(t) == INT4OID || \
379379
(t) == OIDOID || \
380380
(t) == FLOAT4OID || \
381-
(t) == FLOAT8OID)
381+
(t) == FLOAT8OID || \
382+
(t) == CASHOID)
382383

383384
/* binary operator */
384385
ltypeId = (ltree==NULL) ? UNKNOWNOID : exprType(ltree);

src/backend/parser/parser.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.20 1997/08/03 02:28:10 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.21 1997/08/22 00:02:08 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -238,6 +238,13 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
238238
string_palloced = true;
239239
sprintf(const_string,"%f", ((Const)lnext(expr))->constvalue);
240240
break;
241+
242+
case CASHOID: /* money */
243+
const_string = (char *) palloc(256);
244+
string_palloced = true;
245+
sprintf(const_string,"%ld",
246+
(int) ((Const*)expr)->constvalue);
247+
break;
241248

242249
case TEXTOID: /* text */
243250
const_string = DatumGetPointer(((Const)lnext(expr))->constvalue);
@@ -350,6 +357,12 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
350357
sprintf(const_string,"%f", *floatVal);
351358
break;
352359
}
360+
case CASHOID: /* money */
361+
const_string = (char *) palloc(256);
362+
string_palloced = true;
363+
sprintf(const_string,"%ld",
364+
(long) ((Const*)expr)->constvalue);
365+
break;
353366
case TEXTOID: /* text */
354367
const_string =
355368
DatumGetPointer(((Const*)expr)->constvalue );

src/include/catalog/pg_type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_type.h,v 1.14 1997/08/21 01:37:55 vadim Exp $
10+
* $Id: pg_type.h,v 1.15 1997/08/22 00:02:19 momjian Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -242,6 +242,7 @@ DATA(insert OID = 705 ( unknown PGUID -1 -1 f b t \054 0 18 textin textout
242242
DATA(insert OID = 718 ( circle PGUID 24 47 f b t \054 0 0 circle_in circle_out circle_in circle_out d _null_ ));
243243
DATA(insert OID = 719 ( _circle PGUID -1 -1 f b t \054 0 718 array_in array_out array_in array_out d _null_ ));
244244
DATA(insert OID = 790 ( money PGUID 4 24 f b t \054 0 0 cash_in cash_out cash_in cash_out i _null_ ));
245+
#define CASHOID 790
245246
DATA(insert OID = 791 ( _money PGUID -1 -1 f b t \054 0 790 array_in array_out array_in array_out i _null_ ));
246247

247248
/* OIDS 800 - 899 */

0 commit comments

Comments
 (0)