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

Commit45e02e3

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 parentf145454 commit45e02e3

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
@@ -226,6 +226,18 @@ transformArrayType(Oid *arrayType, int32 *arrayTypmod)
226226
*/
227227
*arrayType=getBaseTypeAndTypmod(*arrayType,arrayTypmod);
228228

229+
/*
230+
* We treat int2vector and oidvector as though they were domains over
231+
* int2[] and oid[]. This is needed because array slicing could create an
232+
* array that doesn't satisfy the dimensionality constraints of the
233+
* xxxvector type; so we want the result of a slice operation to be
234+
* considered to be of the more general type.
235+
*/
236+
if (*arrayType==INT2VECTOROID)
237+
*arrayType=INT2ARRAYOID;
238+
elseif (*arrayType==OIDVECTOROID)
239+
*arrayType=OIDARRAYOID;
240+
229241
/* Get the type tuple for the array */
230242
type_tuple_array=SearchSysCache1(TYPEOID,ObjectIdGetDatum(*arrayType));
231243
if (!HeapTupleIsValid(type_tuple_array))
@@ -263,6 +275,7 @@ transformArrayType(Oid *arrayType, int32 *arrayTypmod)
263275
* For both cases, if the source array is of a domain-over-array type,
264276
* the result is of the base array type or its element type; essentially,
265277
* we must fold a domain to its base type before applying subscripting.
278+
* (Note that int2vector and oidvector are treated as domains here.)
266279
*
267280
* pstateParse state
268281
* 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
@@ -839,18 +839,20 @@ transformAssignmentSubscripts(ParseState *pstate,
839839
/* If target was a domain over array, need to coerce up to the domain */
840840
if (arrayType!=targetTypeId)
841841
{
842+
Oidresulttype=exprType(result);
843+
842844
result=coerce_to_target_type(pstate,
843-
result,exprType(result),
845+
result,resulttype,
844846
targetTypeId,targetTypMod,
845847
COERCION_ASSIGNMENT,
846848
COERCE_IMPLICIT_CAST,
847849
-1);
848-
/*probably shouldn'tfail, butcheck */
850+
/*canfail if we had int2vector/oidvector, butnot for true domains */
849851
if (result==NULL)
850852
ereport(ERROR,
851853
(errcode(ERRCODE_CANNOT_COERCE),
852854
errmsg("cannot cast type %s to %s",
853-
format_type_be(exprType(result)),
855+
format_type_be(resulttype),
854856
format_type_be(targetTypeId)),
855857
parser_errposition(pstate,location)));
856858
}

‎src/include/catalog/pg_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,15 @@ DATA(insert OID = 1001 ( _bytea PGNSP PGUID -1 f b A f t \054 017 0 array_in
446446
DATA(insertOID=1002 (_charPGNSPPGUID-1fbAft \0540180array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
447447
DATA(insertOID=1003 (_namePGNSPPGUID-1fbAft \0540190array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
448448
DATA(insertOID=1005 (_int2PGNSPPGUID-1fbAft \0540210array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
449+
#defineINT2ARRAYOID1005
449450
DATA(insertOID=1006 (_int2vectorPGNSPPGUID-1fbAft \0540220array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
450451
DATA(insertOID=1007 (_int4PGNSPPGUID-1fbAft \0540230array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
451452
#defineINT4ARRAYOID1007
452453
DATA(insertOID=1008 (_regprocPGNSPPGUID-1fbAft \0540240array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
453454
DATA(insertOID=1009 (_textPGNSPPGUID-1fbAft \0540250array_inarray_outarray_recvarray_send--array_typanalyzeixf0-10100_null__null__null_ ));
454455
#defineTEXTARRAYOID1009
455456
DATA(insertOID=1028 (_oidPGNSPPGUID-1fbAft \0540260array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
457+
#defineOIDARRAYOID1028
456458
DATA(insertOID=1010 (_tidPGNSPPGUID-1fbAft \0540270array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
457459
DATA(insertOID=1011 (_xidPGNSPPGUID-1fbAft \0540280array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));
458460
DATA(insertOID=1012 (_cidPGNSPPGUID-1fbAft \0540290array_inarray_outarray_recvarray_send--array_typanalyzeixf0-100_null__null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp