|
24 | 24 | #include "mb/pg_wchar.h"
|
25 | 25 | #include "miscadmin.h"
|
26 | 26 | #include "nodes/nodeFuncs.h"
|
| 27 | +#include "parser/parse_coerce.h" |
27 | 28 | #include "utils/array.h"
|
28 | 29 | #include "utils/builtins.h"
|
29 | 30 | #include "utils/hsearch.h"
|
@@ -4044,7 +4045,7 @@ jsonb_subscription_evaluate(PG_FUNCTION_ARGS)
|
4044 | 4045 |
|
4045 | 4046 | path = (text **) palloc(sbsdata->indexprNumber * sizeof(text*));
|
4046 | 4047 | for (i = 0; i < sbsdata->indexprNumber; i++)
|
4047 |
| - path[i] = cstring_to_text((char *) DatumGetPointer(sbsdata->upper[i])); |
| 4048 | + path[i] = DatumGetTextP(sbsdata->upper[i]); |
4048 | 4049 |
|
4049 | 4050 | if (is_assignment)
|
4050 | 4051 | {
|
@@ -4119,13 +4120,45 @@ jsonb_subscription_prepare(PG_FUNCTION_ARGS)
|
4119 | 4120 | {
|
4120 | 4121 | SubscriptionRef *sbsref = (SubscriptionRef *) PG_GETARG_POINTER(0);
|
4121 | 4122 | ParseState *pstate = (ParseState *) PG_GETARG_POINTER(1);
|
| 4123 | + List *upperIndexpr = NIL; |
| 4124 | + ListCell *l; |
4122 | 4125 |
|
4123 | 4126 | if (sbsref->reflowerindexpr != NIL)
|
4124 | 4127 | ereport(ERROR,
|
4125 | 4128 | (errcode(ERRCODE_DATATYPE_MISMATCH),
|
4126 | 4129 | errmsg("jsonb subscript does not support slices"),
|
4127 | 4130 | parser_errposition(pstate, exprLocation(
|
4128 |
| - ((Node *)lfirst(sbsref->reflowerindexpr->head))) ))); |
| 4131 | + ((Node *)lfirst(sbsref->reflowerindexpr->head)))))); |
| 4132 | + |
| 4133 | + foreach(l, sbsref->refupperindexpr) |
| 4134 | + { |
| 4135 | + Node *subexpr = (Node *) lfirst(l); |
| 4136 | + |
| 4137 | + Assert(subexpr != NULL); |
| 4138 | + |
| 4139 | + if (subexpr == NULL) |
| 4140 | + ereport(ERROR, |
| 4141 | + (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 4142 | + errmsg("jsonb subscript does not support slices"), |
| 4143 | + parser_errposition(pstate, exprLocation( |
| 4144 | + ((Node *) lfirst(sbsref->refupperindexpr->head)))))); |
| 4145 | + |
| 4146 | + subexpr = coerce_to_target_type(pstate, |
| 4147 | + subexpr, exprType(subexpr), |
| 4148 | + TEXTOID, -1, |
| 4149 | + COERCION_ASSIGNMENT, |
| 4150 | + COERCE_IMPLICIT_CAST, |
| 4151 | + -1); |
| 4152 | + if (subexpr == NULL) |
| 4153 | + ereport(ERROR, |
| 4154 | + (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 4155 | + errmsg("jsonb subscript must have text type"), |
| 4156 | + parser_errposition(pstate, exprLocation(subexpr)))); |
| 4157 | + |
| 4158 | + upperIndexpr = lappend(upperIndexpr, subexpr); |
| 4159 | + } |
| 4160 | + |
| 4161 | + sbsref->refupperindexpr = upperIndexpr; |
4129 | 4162 |
|
4130 | 4163 | PG_RETURN_POINTER(sbsref);
|
4131 | 4164 | }
|
|
0 commit comments