-- check whether we can handle arrays of maximum dimension (6) select plperl_sum_array(ARRAY[[[[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],
[[13,14],[15,16]]]],
[[[[17,18],[19,20]],[[21,22],[23,24]]],[[[25,26],[27,28]],[[29,30],[31,32]]]]],
[[[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]],
[[[[17,18],[19,20]],[[21,22],[23,24]]],[[[25,26],[27,28]],[[29,30],[31,32]]]]]]);
-- what would we do with the arrays exceeding maximum dimension (7) select plperl_sum_array('{{{{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},
{{13,14},{15,16}}}},
{{{{17,18},{19,20}},{{21,22},{23,24}}},{{{25,26},{27,28}},{{29,30},{31,32}}}}},
{{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}}}},
{{{{17,18},{19,20}},{{21,22},{23,24}}},{{{25,26},{27,28}},{{29,30},{31,32}}}}}},
{{{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}}}},
{{{{17,18},{19,20}},{{21,22},{23,24}}},{{{25,26},{27,28}},{{29,30},{31,32}}}}},
{{{{{1,2},{3,4}},{{5,6},{7,8}}},{{{9,10},{11,12}},{{13,14},{15,16}}}},
{{{{17,18},{19,20}},{{21,22},{23,24}}},{{{25,26},{27,28}},{{29,30},{31,32}}}}}}}'
);
-- array of rows -- CREATE TYPE foo AS (bar INTEGER, baz TEXT); CREATEORREPLACE FUNCTION plperl_array_of_rows(foo[]) RETURNS TEXT AS $$
my $array_arg = shift;
my $result = "";
for my $row_ref (@$array_arg) {
die "not a hash reference" unless (ref $row_ref eq "HASH");
$result .= $row_ref->{bar}." items of ".$row_ref->{baz}.";";
} return $result .' '. $array_arg;
$$ LANGUAGE plperl;
-- composite type containing array of another composite type, which, in order, -- contains an array of integers. CREATE TYPE rowbar AS (foo rowfoo[]);
CREATEORREPLACE FUNCTION plperl_sum_array_of_rows(rowbar) RETURNS TEXT AS $$
my $rowfoo_ref = shift;
my $result = 0;
if (ref $rowfoo_ref eq 'HASH') {
my $row_array_ref = $rowfoo_ref->{foo}; if (is_array_ref($row_array_ref)) {
foreach my $row_ref (@{$row_array_ref}) { if (ref $row_ref eq 'HASH') {
$result += $row_ref->{bar};
die "not an array reference".ref ($row_ref->{baz})
unless (is_array_ref($row_ref->{baz}));
foreach my $elem (@{$row_ref->{baz}}) {
$result += $elem unless ref $elem;
}
} else {
die "element baz is not a reference to a rowfoo";
}
}
} else {
die "not a reference to an array of rowfoo elements"
}
} else {
die "not a reference to type rowbar";
} return $result;
$$ LANGUAGE plperl;
-- check arrays as out parameters CREATEORREPLACE FUNCTION plperl_arrays_out(OUTINTEGER[]) AS $$ return [[1,2,3],[4,5,6]];
$$ LANGUAGE plperl;
select plperl_arrays_out();
-- check that we can return the array we passed in CREATEORREPLACE FUNCTION plperl_arrays_inout(INTEGER[]) returns INTEGER[] AS $$ return shift;
$$ LANGUAGE plperl;
select plperl_arrays_inout('{{1}, {2}, {3}}');
-- check that we can return an array literal CREATEORREPLACE FUNCTION plperl_arrays_inout_l(INTEGER[]) returns INTEGER[] AS $$ return shift.''; # stringify it
$$ LANGUAGE plperl;
select plperl_arrays_inout_l('{{1}, {2}, {3}}');
-- check output of multi-dimensional arrays CREATE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [['a'], ['b'], ['c']];
$$ LANGUAGE plperl;
select plperl_md_array_out();
CREATEORREPLACE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [[], []];
$$ LANGUAGE plperl;
select plperl_md_array_out();
CREATEORREPLACE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [[], [1]];
$$ LANGUAGE plperl;
select plperl_md_array_out(); -- fail
CREATEORREPLACE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [[], 1];
$$ LANGUAGE plperl;
select plperl_md_array_out(); -- fail
CREATEORREPLACE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [1, []];
$$ LANGUAGE plperl;
select plperl_md_array_out(); -- fail
CREATEORREPLACE FUNCTION plperl_md_array_out() RETURNS text[] AS $$ return [[1], [[]]];
$$ LANGUAGE plperl;
select plperl_md_array_out(); -- fail
-- make sure setof works createorreplace function perl_setof_array(integer[]) returns setof integer[] language plperl as $$
my $arr = shift; for my $r (@$arr) {
return_next $r;
} return undef;
$$;
select perl_setof_array('{{1}, {2}, {3}}');
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-08-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.