Skip to content

Commit bbbd807

Browse files
committed
Revert 9246af6 because
I miss too much. Patch is returned to commitfest process.
1 parent 3c7042a commit bbbd807

File tree

12 files changed

+28
-184
lines changed

12 files changed

+28
-184
lines changed

doc/src/sgml/array.sgml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,6 @@ SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
255255
------------------------
256256
{{meeting},{training}}
257257
(1 row)
258-
</programlisting>
259-
260-
Possible to skip the <literal><replaceable>lower-bound</replaceable></literal> or
261-
<literal><replaceable>upper-bound</replaceable></literal>
262-
for get first or last element in slice.
263-
264-
<programlisting>
265-
SELECT schedule[:][:] FROM sal_emp WHERE name = 'Bill';
266-
267-
schedule
268-
------------------------
269-
{{meeting,lunch},{training,presentation}}
270-
(1 row)
271-
272-
SELECT schedule[:2][2:] FROM sal_emp WHERE name = 'Bill';
273-
274-
schedule
275-
------------------------
276-
{{lunch},{presentation}}
277-
(1 row)
278258
</programlisting>
279259

280260
If any dimension is written as a slice, i.e., contains a colon, then all

src/backend/executor/execQual.c

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,10 @@ ExecEvalArrayRef(ArrayRefExprState *astate,
268268
bool eisnull;
269269
ListCell *l;
270270
int i = 0,
271-
j = 0,
272-
indexexpr;
271+
j = 0;
273272
IntArray upper,
274273
lower;
275274
int *lIndex;
276-
AnyArrayType *arrays;
277275

278276
array_source = ExecEvalExpr(astate->refexpr,
279277
econtext,
@@ -295,31 +293,17 @@ ExecEvalArrayRef(ArrayRefExprState *astate,
295293
foreach(l, astate->refupperindexpr)
296294
{
297295
ExprState *eltstate = (ExprState *) lfirst(l);
298-
eisnull = false;
299296

300297
if (i >= MAXDIM)
301298
ereport(ERROR,
302299
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
303300
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
304301
i + 1, MAXDIM)));
305302

306-
if (eltstate == NULL && astate->refattrlength <= 0)
307-
{
308-
if (isAssignment)
309-
ereport(ERROR,
310-
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
311-
errmsg("cannot determine upper index for empty array")));
312-
arrays = (AnyArrayType *)DatumGetArrayTypeP(array_source);
313-
indexexpr = AARR_LBOUND(arrays)[i] + AARR_DIMS(arrays)[i] - 1;
314-
}
315-
else
316-
indexexpr = DatumGetInt32(ExecEvalExpr(eltstate,
317-
econtext,
318-
&eisnull,
319-
NULL));
320-
321-
upper.indx[i++] = indexexpr;
322-
303+
upper.indx[i++] = DatumGetInt32(ExecEvalExpr(eltstate,
304+
econtext,
305+
&eisnull,
306+
NULL));
323307
/* If any index expr yields NULL, result is NULL or error */
324308
if (eisnull)
325309
{
@@ -337,27 +321,17 @@ ExecEvalArrayRef(ArrayRefExprState *astate,
337321
foreach(l, astate->reflowerindexpr)
338322
{
339323
ExprState *eltstate = (ExprState *) lfirst(l);
340-
eisnull = false;
341324

342325
if (j >= MAXDIM)
343326
ereport(ERROR,
344327
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
345328
errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
346329
j + 1, MAXDIM)));
347330

348-
if (eltstate == NULL)
349-
{
350-
arrays = (AnyArrayType *)DatumGetArrayTypeP(array_source);
351-
indexexpr = AARR_LBOUND(arrays)[j];
352-
}
353-
else
354-
indexexpr = DatumGetInt32(ExecEvalExpr(eltstate,
355-
econtext,
356-
&eisnull,
357-
NULL));
358-
359-
lower.indx[j++] = indexexpr;
360-
331+
lower.indx[j++] = DatumGetInt32(ExecEvalExpr(eltstate,
332+
econtext,
333+
&eisnull,
334+
NULL));
361335
/* If any index expr yields NULL, result is NULL or error */
362336
if (eisnull)
363337
{

src/backend/nodes/copyfuncs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,8 +2403,6 @@ _copyAIndices(const A_Indices *from)
24032403

24042404
COPY_NODE_FIELD(lidx);
24052405
COPY_NODE_FIELD(uidx);
2406-
COPY_SCALAR_FIELD(lidx_default);
2407-
COPY_SCALAR_FIELD(uidx_default);
24082406

24092407
return newnode;
24102408
}

src/backend/nodes/equalfuncs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,8 +2153,6 @@ _equalAIndices(const A_Indices *a, const A_Indices *b)
21532153
{
21542154
COMPARE_NODE_FIELD(lidx);
21552155
COMPARE_NODE_FIELD(uidx);
2156-
COMPARE_SCALAR_FIELD(lidx_default);
2157-
COMPARE_SCALAR_FIELD(uidx_default);
21582156

21592157
return true;
21602158
}

src/backend/nodes/outfuncs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,8 +2765,6 @@ _outA_Indices(StringInfo str, const A_Indices *node)
27652765

27662766
WRITE_NODE_FIELD(lidx);
27672767
WRITE_NODE_FIELD(uidx);
2768-
WRITE_BOOL_FIELD(lidx_default);
2769-
WRITE_BOOL_FIELD(uidx_default);
27702768
}
27712769

27722770
static void

src/backend/parser/gram.y

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13193,44 +13193,13 @@ indirection_el:
1319313193
A_Indices *ai = makeNode(A_Indices);
1319413194
ai->lidx = NULL;
1319513195
ai->uidx = $2;
13196-
ai->lidx_default = false;
13197-
ai->uidx_default = false;
13198-
$$ = (Node *) ai;
13199-
}
13200-
| '[' ':' ']'
13201-
{
13202-
A_Indices *ai = makeNode(A_Indices);
13203-
ai->lidx = NULL;
13204-
ai->uidx = NULL;
13205-
ai->lidx_default = true;
13206-
ai->uidx_default = true;
13207-
$$ = (Node *) ai;
13208-
}
13209-
| '[' ':' a_expr ']'
13210-
{
13211-
A_Indices *ai = makeNode(A_Indices);
13212-
ai->lidx = NULL;
13213-
ai->uidx = $3;
13214-
ai->lidx_default = true;
13215-
ai->uidx_default = false;
13216-
$$ = (Node *) ai;
13217-
}
13218-
| '[' a_expr ':' ']'
13219-
{
13220-
A_Indices *ai = makeNode(A_Indices);
13221-
ai->lidx = $2;
13222-
ai->uidx = NULL;
13223-
ai->lidx_default = false;
13224-
ai->uidx_default = true;
1322513196
$$ = (Node *) ai;
1322613197
}
1322713198
| '[' a_expr ':' a_expr ']'
1322813199
{
1322913200
A_Indices *ai = makeNode(A_Indices);
1323013201
ai->lidx = $2;
1323113202
ai->uidx = $4;
13232-
ai->lidx_default = false;
13233-
ai->uidx_default = false;
1323413203
$$ = (Node *) ai;
1323513204
}
1323613205
;

src/backend/parser/parse_node.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ transformArraySubscripts(ParseState *pstate,
311311
elementType = transformArrayType(&arrayType, &arrayTypMod);
312312

313313
/*
314-
* A list containing only single subscripts (uidx) refers to a single array
314+
* A list containing only single subscripts refers to a single array
315315
* element. If any of the items are double subscripts (lower:upper), then
316316
* the subscript expression means an array slice operation. In this case,
317317
* we supply a default lower bound of 1 for any items that contain only a
@@ -322,7 +322,7 @@ transformArraySubscripts(ParseState *pstate,
322322
{
323323
A_Indices *ai = (A_Indices *) lfirst(idx);
324324

325-
if (ai->lidx != NULL || ai->lidx_default)
325+
if (ai->lidx != NULL)
326326
{
327327
isSlice = true;
328328
break;
@@ -335,17 +335,9 @@ transformArraySubscripts(ParseState *pstate,
335335
foreach(idx, indirection)
336336
{
337337
A_Indices *ai = (A_Indices *) lfirst(idx);
338-
Node *subexpr = NULL;
338+
Node *subexpr;
339339

340340
Assert(IsA(ai, A_Indices));
341-
if ((ai->uidx_default || ai->lidx_default) && assignFrom != NULL)
342-
ereport(ERROR,
343-
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
344-
errmsg("array subscript must have both boundaries"),
345-
errhint("You can't omit the upper or lower"
346-
" boundaries when updating or inserting"),
347-
parser_errposition(pstate, exprLocation(arrayBase))));
348-
349341
if (isSlice)
350342
{
351343
if (ai->lidx)
@@ -364,7 +356,7 @@ transformArraySubscripts(ParseState *pstate,
364356
errmsg("array subscript must have type integer"),
365357
parser_errposition(pstate, exprLocation(ai->lidx))));
366358
}
367-
else if (ai->lidx_default == false)
359+
else
368360
{
369361
/* Make a constant 1 */
370362
subexpr = (Node *) makeConst(INT4OID,
@@ -377,26 +369,19 @@ transformArraySubscripts(ParseState *pstate,
377369
}
378370
lowerIndexpr = lappend(lowerIndexpr, subexpr);
379371
}
380-
381-
if (ai->uidx_default == false)
382-
{
383-
subexpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind);
384-
/* If it's not int4 already, try to coerce */
385-
subexpr = coerce_to_target_type(pstate,
386-
subexpr, exprType(subexpr),
387-
INT4OID, -1,
388-
COERCION_ASSIGNMENT,
389-
COERCE_IMPLICIT_CAST,
390-
-1);
391-
if (subexpr == NULL)
392-
ereport(ERROR,
393-
(errcode(ERRCODE_DATATYPE_MISMATCH),
394-
errmsg("array subscript must have type integer"),
395-
parser_errposition(pstate, exprLocation(ai->uidx))));
396-
}
397-
else
398-
subexpr = NULL;
399-
372+
subexpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind);
373+
/* If it's not int4 already, try to coerce */
374+
subexpr = coerce_to_target_type(pstate,
375+
subexpr, exprType(subexpr),
376+
INT4OID, -1,
377+
COERCION_ASSIGNMENT,
378+
COERCE_IMPLICIT_CAST,
379+
-1);
380+
if (subexpr == NULL)
381+
ereport(ERROR,
382+
(errcode(ERRCODE_DATATYPE_MISMATCH),
383+
errmsg("array subscript must have type integer"),
384+
parser_errposition(pstate, exprLocation(ai->uidx))));
400385
upperIndexpr = lappend(upperIndexpr, subexpr);
401386
}
402387

src/backend/parser/parse_target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ transformAssignmentIndirection(ParseState *pstate,
650650
if (IsA(n, A_Indices))
651651
{
652652
subscripts = lappend(subscripts, n);
653-
if (((A_Indices *) n)->lidx != NULL || ((A_Indices *) n)->lidx_default)
653+
if (((A_Indices *) n)->lidx != NULL)
654654
isSlice = true;
655655
}
656656
else if (IsA(n, A_Star))

src/include/nodes/parsenodes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ typedef struct A_Indices
358358
NodeTag type;
359359
Node *lidx; /* NULL if it's a single subscript */
360360
Node *uidx;
361-
bool lidx_default;
362-
bool uidx_default;
363361
} A_Indices;
364362

365363
/*

src/test/regress/expected/arrays.out

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,43 +2031,3 @@ SELECT width_bucket(5, ARRAY[3, 4, NULL]);
20312031
ERROR: thresholds array must not contain NULLs
20322032
SELECT width_bucket(5, ARRAY[ARRAY[1, 2], ARRAY[3, 4]]);
20332033
ERROR: thresholds must be one-dimensional array
2034-
-- slices with empty lower and/or upper index
2035-
CREATE TABLE arrtest_s (
2036-
a int2[],
2037-
b int2[][]
2038-
);
2039-
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
2040-
SELECT a[:3], b[:2][:2] FROM arrtest_s;
2041-
a | b
2042-
---------+---------------
2043-
{1,2,3} | {{1,2},{4,5}}
2044-
(1 row)
2045-
2046-
SELECT a[2:], b[2:][2:] FROM arrtest_s;
2047-
a | b
2048-
-----------+---------------
2049-
{2,3,4,5} | {{5,6},{8,9}}
2050-
(1 row)
2051-
2052-
SELECT a[:], b[:] FROM arrtest_s;
2053-
a | b
2054-
-------------+---------------------------
2055-
{1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
2056-
(1 row)
2057-
2058-
-- errors
2059-
UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14, 15}}';
2060-
ERROR: array subscript must have both boundaries
2061-
LINE 1: UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{...
2062-
^
2063-
HINT: You can't omit the upper or lower boundaries when updating or inserting
2064-
UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28, 29}}';
2065-
ERROR: array subscript must have both boundaries
2066-
LINE 1: UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{...
2067-
^
2068-
HINT: You can't omit the upper or lower boundaries when updating or inserting
2069-
UPDATE arrtest_s SET a[:] = '{23, 24, 25}';
2070-
ERROR: array subscript must have both boundaries
2071-
LINE 1: UPDATE arrtest_s SET a[:] = '{23, 24, 25}';
2072-
^
2073-
HINT: You can't omit the upper or lower boundaries when updating or inserting

src/test/regress/output/misc.source

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ SELECT user_relns() AS user_relns
586586
array_index_op_test
587587
array_op_test
588588
arrtest
589-
arrtest_s
590589
b
591590
b_star
592591
bb
@@ -711,7 +710,7 @@ SELECT user_relns() AS user_relns
711710
tvvmv
712711
varchar_tbl
713712
xacttest
714-
(133 rows)
713+
(132 rows)
715714

716715
SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer')));
717716
name

src/test/regress/sql/arrays.sql

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -609,18 +609,3 @@ SELECT width_bucket(5, '{}');
609609
SELECT width_bucket('5'::text, ARRAY[3, 4]::integer[]);
610610
SELECT width_bucket(5, ARRAY[3, 4, NULL]);
611611
SELECT width_bucket(5, ARRAY[ARRAY[1, 2], ARRAY[3, 4]]);
612-
613-
-- slices with empty lower and/or upper index
614-
CREATE TABLE arrtest_s (
615-
a int2[],
616-
b int2[][]
617-
);
618-
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
619-
SELECT a[:3], b[:2][:2] FROM arrtest_s;
620-
SELECT a[2:], b[2:][2:] FROM arrtest_s;
621-
SELECT a[:], b[:] FROM arrtest_s;
622-
623-
-- errors
624-
UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14, 15}}';
625-
UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28, 29}}';
626-
UPDATE arrtest_s SET a[:] = '{23, 24, 25}';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy