| From: | Tjibbe <tjibbe(at)rijpma(dot)org> |
|---|---|
| To: | PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org> |
| Subject: | push array to array |
| Date: | 2016-09-18 16:46:10 |
| Message-ID: | CAF_dx11uKCXmaxMpYd42wxh1iRmFsbJx-t-HTDeaXybdX88vcQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
I would like to push an array at the end of an array. Like:
'{{4,5},{8,3}}' + '{3,6}' > '{{4,5},{8,3},{3,6}}'
Is there an easy way to do? (i have version "9.1.23" on my shared hosting)
Now I have written a complex function with EXECUTE command-string...
CREATE OR REPLACE FUNCTION push_2d_array(numeric[],numeric[]) RETURNS
numeric[] AS $$
DECLARE
_str text;
_arr numeric[];
BEGIN
IF $1 IS NULL THEN
RETURN ARRAY[$2];
ELSE
_str := 'SELECT ARRAY[';
FOR i in 1..array_upper($1,1) LOOP
IF i > 1 THEN _str := _str || ','; END IF;
_str := _str || 'ARRAY[' || $1[i][1] || ',' || $1[i][2] || ']';
END LOOP;
_str := _str || ', ARRAY[' || $2[1] || ',' || $2[2] || ']]';
EXECUTE _str INTO _arr ;
RETURN _arr;
END IF;
END
$$ LANGUAGE plpgsql;
--
+31 6 29401726
tjibbe(at)rijpma(dot)org
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavel Stehule | 2016-09-18 17:12:53 | Re: push array to array |
| Previous Message | Andomar | 2016-09-18 11:17:15 | SO question about disappearing row |