Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b63528

Browse files
committed
Fix array slicing of int2vector and oidvector values.
The previous coding labeled expressions such as pg_index.indkey[1:3] asbeing of int2vector type; which is not right because the subscript boundsof such a result don't, in general, satisfy the restrictions of int2vector.To fix, implicitly promote the result of slicing int2vector to int2[],or oidvector to oid[]. This is similar to what we've done with domainsover arrays, which is a good analogy because these types are very muchlike restricted domains of the corresponding regular-array types.A side-effect is that we now also forbid array-element updates on suchcolumns, eg while "update pg_index set indkey[4] = 42" would have workedbefore if you were superuser (and corrupted your catalogs irretrievably,no doubt) it's now disallowed. This seems like a good thing since, again,some choices of subscripting would've led to results not satisfying therestrictions of int2vector. The case of an array-slice update wasrejected before, though with a different error message than you get now.We could make these cases work in future if we added a cast from int2[]to int2vector (with a cast function checking the subscript restrictions)but it seems unlikely that there's any value in that.Per report from Ronan Dunklau. Back-patch to all supported branchesbecause of the crash risks involved.
1 parentb2502ec commit7b63528

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

‎src/backend/parser/parse_node.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ transformArrayType(Oid *arrayType, int32 *arrayTypmod)
225225
*/
226226
*arrayType=getBaseTypeAndTypmod(*arrayType,arrayTypmod);
227227

228+
/*
229+
* We treat int2vector and oidvector as though they were domains over
230+
* int2[] and oid[]. This is needed because array slicing could create an
231+
* array that doesn't satisfy the dimensionality constraints of the
232+
* xxxvector type; so we want the result of a slice operation to be
233+
* considered to be of the more general type.
234+
*/
235+
if (*arrayType==INT2VECTOROID)
236+
*arrayType=INT2ARRAYOID;
237+
elseif (*arrayType==OIDVECTOROID)
238+
*arrayType=OIDARRAYOID;
239+
228240
/* Get the type tuple for the array */
229241
type_tuple_array=SearchSysCache1(TYPEOID,ObjectIdGetDatum(*arrayType));
230242
if (!HeapTupleIsValid(type_tuple_array))
@@ -262,6 +274,7 @@ transformArrayType(Oid *arrayType, int32 *arrayTypmod)
262274
* For both cases, if the source array is of a domain-over-array type,
263275
* the result is of the base array type or its element type; essentially,
264276
* we must fold a domain to its base type before applying subscripting.
277+
* (Note that int2vector and oidvector are treated as domains here.)
265278
*
266279
* pstateParse state
267280
* arrayBaseAlready-transformed expression for the array as a whole

‎src/backend/parser/parse_target.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,20 @@ transformAssignmentSubscripts(ParseState *pstate,
817817
/* If target was a domain over array, need to coerce up to the domain */
818818
if (arrayType!=targetTypeId)
819819
{
820+
Oidresulttype=exprType(result);
821+
820822
result=coerce_to_target_type(pstate,
821-
result,exprType(result),
823+
result,resulttype,
822824
targetTypeId,targetTypMod,
823825
COERCION_ASSIGNMENT,
824826
COERCE_IMPLICIT_CAST,
825827
-1);
826-
/*probably shouldn'tfail, butcheck */
828+
/*canfail if we had int2vector/oidvector, butnot for true domains */
827829
if (result==NULL)
828830
ereport(ERROR,
829831
(errcode(ERRCODE_CANNOT_COERCE),
830832
errmsg("cannot cast type %s to %s",
831-
format_type_be(exprType(result)),
833+
format_type_be(resulttype),
832834
format_type_be(targetTypeId)),
833835
parser_errposition(pstate,location)));
834836
}

‎src/include/catalog/pg_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,15 @@ DATA(insert OID = 1001 ( _bytea PGNSP PGUID -1 f b A f t \054 017 0 array_in
436436
DATA(insertOID=1002 (_charPGNSPPGUID-1fbAft \0540180array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
437437
DATA(insertOID=1003 (_namePGNSPPGUID-1fbAft \0540190array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
438438
DATA(insertOID=1005 (_int2PGNSPPGUID-1fbAft \0540210array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
439+
#defineINT2ARRAYOID1005
439440
DATA(insertOID=1006 (_int2vectorPGNSPPGUID-1fbAft \0540220array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
440441
DATA(insertOID=1007 (_int4PGNSPPGUID-1fbAft \0540230array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
441442
#defineINT4ARRAYOID1007
442443
DATA(insertOID=1008 (_regprocPGNSPPGUID-1fbAft \0540240array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
443444
DATA(insertOID=1009 (_textPGNSPPGUID-1fbAft \0540250array_inarray_outarray_recvarray_send---ixf0-10100_null__null_ ));
444445
#defineTEXTARRAYOID1009
445446
DATA(insertOID=1028 (_oidPGNSPPGUID-1fbAft \0540260array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
447+
#defineOIDARRAYOID1028
446448
DATA(insertOID=1010 (_tidPGNSPPGUID-1fbAft \0540270array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
447449
DATA(insertOID=1011 (_xidPGNSPPGUID-1fbAft \0540280array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));
448450
DATA(insertOID=1012 (_cidPGNSPPGUID-1fbAft \0540290array_inarray_outarray_recvarray_send---ixf0-100_null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp