From: | Jim Nasby <decibel(at)decibel(dot)org> |
---|---|
To: | orehon <lucascarvalho(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Function to ADD a value into each column of real[] |
Date: | 2007-07-13 15:49:11 |
Message-ID: | 758A2CE8-C311-4050-8141-7D54B8F59948@decibel.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Jul 10, 2007, at 2:38 PM, orehon wrote:
> Hello,
> if I have this table:
> CREATE TABLE teste (
> id integer,
> picos real[],
> );
>
> and insert this values:
> INSERT INTO teste VALUES(1, '{{1,2,3},{1,2,3},{1,2,3},{1,2,3},
> {1,2,3}}');
> INSERT INTO teste VALUES(2, '{{1,2,3},{1,2,3},{1,2,3},{1,2,3},{1,2,3},
> {1,2,3},{1,2,3}}');
> INSERT INTO teste VALUES(3, '{{1,2,3},{1,2,3},{1,2,3},{1,2,3},{1,2,3},
> {1,2,3},{1,2,3},{1,2,3}}');
> INSERT INTO teste VALUES(4, '{{1,2,3},{1,2,3},{1,2,3}}');
>
> I need to write a function to return all the record of this table and
> add a 0 in the begin of each array.
> Ex.:
>
> 1, {{0,1,2,3},{0,1,2,3},{0,1,2,3},{0,1,2,3},{0,1,2,3}}
> .............
You'll need something like...
FOR i IN array_lower(array, 1) .. array_upper(array, 1)
array[i] := 0 || array[i];
END
You might need some special logic to handle either the second pass
through the loop if this ends up giving you a single-dimension array.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
From | Date | Subject | |
---|---|---|---|
Next Message | Zlatko Matić | 2007-07-13 16:50:26 | multirow insert |
Previous Message | Jim Nasby | 2007-07-13 15:44:07 | Re: TOAST, large objects, and ACIDity |