From: | Julia Jacobson <julia(dot)jacobson(at)arcor(dot)de> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | SELECT INTO array[i] with PL/pgSQL |
Date: | 2011-02-07 21:15:00 |
Message-ID: | 4D5060D4.2020904@arcor.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Dear PostgreSQL community,
Please consider the following minimal example:
CREATE TABLE example (row_id SERIAL, value TEXT);
INSERT INTO example(value) VALUES ('val1');
INSERT INTO example(value) VALUES ('val2');
INSERT INTO example(value) VALUES ('val3');
CREATE OR REPLACE FUNCTION foo()
RETURNS TEXT
AS
$$
DECLARE
a TEXT;
b TEXT[];
i INT;
BEGIN
FOR i in 1..3 LOOP
SELECT INTO a value FROM example WHERE row_id=i; -- This works
b[i] := a; -- perfectly!
-- SELECT INTO b[i] value FROM example WHERE row_id=i; Doesn't work!
END LOOP;
RETURN b[2];
END;
$$
LANGUAGE 'plpgsql';
The error message indicates a problem with selecting values into an array.
I have read the documentation carefully and have done extensive web
search, but a more verbose error message and some additional explanation
would help me to understand the problem.
Is there a way to select values directly into an array without the
assignment from an additional variable?
Regards,
Julia
From | Date | Subject | |
---|---|---|---|
Next Message | Edoardo Panfili | 2011-02-07 22:06:23 | Re: SELECT INTO array[i] with PL/pgSQL |
Previous Message | Oleg Bartunov | 2011-02-07 20:48:20 | Re: fulltext search and hunspell |