|
7 | 7 | #include "utils/builtins.h"
|
8 | 8 | #include "utils/elog.h"
|
9 | 9 | #include "utils/lsyscache.h"
|
| 10 | +#include "utils/syscache.h" |
10 | 11 | #include "utils/rel.h"
|
11 | 12 | #include "utils/fmgroids.h"
|
12 | 13 | #include "utils/memutils.h"
|
13 | 14 | #include "storage/bufmgr.h"
|
14 | 15 | #include "catalog/pg_am.h"
|
15 | 16 | #include "catalog/pg_proc.h"
|
16 | 17 | #include "catalog/pg_operator.h"
|
| 18 | +#include "catalog/pg_cast.h" |
17 | 19 | #include "commands/explain.h"
|
18 | 20 | #include "commands/defrem.h"
|
19 | 21 | #include "funcapi.h"
|
@@ -133,16 +135,34 @@ float8_to_cstring(float8 val)
|
133 | 135 | static float8
|
134 | 136 | get_const_val(Const *node)
|
135 | 137 | {
|
136 |
| - FmgrInfo finfo; |
137 |
| - Oid cast; |
| 138 | + FmgrInfo finfo; |
| 139 | + Oid cast_func; |
| 140 | + HeapTuple cast_tup; |
| 141 | + Form_pg_cast cast; |
138 | 142 |
|
139 | 143 | Assert(IsA(node, Const));
|
140 | 144 |
|
141 | 145 | if (node->consttype == FLOAT8OID)
|
142 | 146 | return DatumGetFloat8(node->constvalue);
|
143 | 147 |
|
144 |
| - cast = get_cast_oid(node->consttype, FLOAT8OID, false); |
145 |
| - fmgr_info(cast, &finfo); |
| 148 | + /* It looks like this is not necessary at all, but anyway */ |
| 149 | + cast_tup = SearchSysCache2(CASTSOURCETARGET, |
| 150 | + ObjectIdGetDatum(node->consttype), |
| 151 | + ObjectIdGetDatum(FLOAT8OID)); |
| 152 | + |
| 153 | + if (!HeapTupleIsValid(cast_tup)) |
| 154 | + ereport(ERROR, |
| 155 | + (errcode(ERRCODE_DUPLICATE_OBJECT), |
| 156 | + errmsg("no cast from type %s to type %s", |
| 157 | + format_type_be(node->consttype), |
| 158 | + format_type_be(FLOAT8OID)))); |
| 159 | + |
| 160 | + cast = (Form_pg_cast) GETSTRUCT(cast_tup); |
| 161 | + cast_func = cast->castfunc; |
| 162 | + |
| 163 | + ReleaseSysCache(cast_tup); |
| 164 | + |
| 165 | + fmgr_info(cast_func, &finfo); |
146 | 166 |
|
147 | 167 | return DatumGetFloat8(FunctionCall1(&finfo, node->constvalue));
|
148 | 168 | }
|
|
0 commit comments