8000 fix get_const_val() · postgrespro/pgsphere@54246dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 54246dd

Browse files
committed
fix get_const_val()
1 parent 1e3bf66 commit 54246dd

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

init.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
#include "utils/builtins.h"
88
#include "utils/elog.h"
99
#include "utils/lsyscache.h"
10+
#include "utils/syscache.h"
1011
#include "utils/rel.h"
1112
#include "utils/fmgroids.h"
1213
#include "utils/memutils.h"
1314
#include "storage/bufmgr.h"
1415
#include "catalog/pg_am.h"
1516
#include "catalog/pg_proc.h"
1617
#include "catalog/pg_operator.h"
18+
#include "catalog/pg_cast.h"
1719
#include "commands/explain.h"
1820
#include "commands/defrem.h"
1921
#include "funcapi.h"
@@ -133,16 +135,34 @@ float8_to_cstring(float8 val)
133135
static float8
134136
get_const_val(Const *node)
135137
{
136-
FmgrInfo finfo;
137-
Oid cast;
138+
FmgrInfo finfo;
139+
Oid cast_func;
140+
HeapTuple cast_tup;
141+
Form_pg_cast cast;
138142

139143
Assert(IsA(node, Const));
140144

141145
if (node->consttype == FLOAT8OID)
142146
return DatumGetFloat8(node->constvalue);
143147

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);
146166

147167
return DatumGetFloat8(FunctionCall1(&finfo, node->constvalue));
148168
}

0 commit comments

Comments
 (0)
0