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

Commit747dd97

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 parentec6a6a2 commit747dd97

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎src/backend/parser/parse_node.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ transformArraySubscripts(ParseState *pstate,
270270
if (!OidIsValid(elementType))
271271
elementType=transformArrayType(arrayType);
272272

273+
/*
274+
* We treat int2vector and oidvector as though they were domains over
275+
* int2[] and oid[]. This is needed because array slicing could create an
276+
* array that doesn't satisfy the dimensionality constraints of the
277+
* xxxvector type; so we want the result of a slice operation to be
278+
* considered to be of the more general type.
279+
*/
280+
if (arrayType==INT2VECTOROID)
281+
arrayType=INT2ARRAYOID;
282+
elseif (arrayType==OIDVECTOROID)
283+
arrayType=OIDARRAYOID;
284+
273285
/*
274286
* A list containing only single subscripts refers to a single array
275287
* element. If any of the items are double subscripts (lower:upper), then

‎src/include/catalog/pg_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,15 @@ DATA(insert OID = 1001 ( _bytea PGNSP PGUID -1 f b A f t \054 017 0 array_in
426426
DATA(insertOID=1002 (_charPGNSPPGUID-1fbAft \0540180array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
427427
DATA(insertOID=1003 (_namePGNSPPGUID-1fbAft \0540190array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
428428
DATA(insertOID=1005 (_int2PGNSPPGUID-1fbAft \0540210array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
429+
#defineINT2ARRAYOID1005
429430
DATA(insertOID=1006 (_int2vectorPGNSPPGUID-1fbAft \0540220array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
430431
DATA(insertOID=1007 (_int4PGNSPPGUID-1fbAft \0540230array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
431432
#defineINT4ARRAYOID1007
432433
DATA(insertOID=1008 (_regprocPGNSPPGUID-1fbAft \0540240array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
433434
DATA(insertOID=1009 (_textPGNSPPGUID-1fbAft \0540250array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
434435
#defineTEXTARRAYOID1009
435436
DATA(insertOID=1028 (_oidPGNSPPGUID-1fbAft \0540260array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
437+
#defineOIDARRAYOID1028
436438
DATA(insertOID=1010 (_tidPGNSPPGUID-1fbAft \0540270array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
437439
DATA(insertOID=1011 (_xidPGNSPPGUID-1fbAft \0540280array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));
438440
DATA(insertOID=1012 (_cidPGNSPPGUID-1fbAft \0540290array_inarray_outarray_recvarray_send---ixf0-10_null__null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp