Array from INSERT .. RETURNING in plpgsql?

Поиск
Список
Период
Сортировка
От Erik Jones
Тема Array from INSERT .. RETURNING in plpgsql?
Дата
Msg-id B9125BC2-D3BD-470A-8116-B31C317611FA@engineyard.com
обсуждение исходный текст
Ответы Re: Array from INSERT .. RETURNING in plpgsql?
Список pgsql-sql
Ok, so the following works:

pagila=# select array(select s.i from generate_series(1, 10) s(i));          ?column?  ------------------------
{1,2,3,4,5,6,7,8,9,10}           (1 row)

but this doesn't:

pagila=# create or replace function testfun() returns void as $$
declare    vals int[];    query text;
begin    query := 'insert into test select s.i from generate_series(1,10)  
s(i) returning i;';    execute query into vals;    raise notice 'vals dim: %', array_upper(vals, 1);    raise notice
'vals[3]:%', vals[3];
 
end;
$$ language plpgsql;
CREATE FUNCTION
Time: 3.319 ms
pagila=# select testfun();
ERROR:  array value must start with "{" or dimension information
CONTEXT:  PL/pgSQL function "testfun" line 6 at execute statement

Is there any way to do what I'm trying without explicity looping over  
the results of the insert?

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
(415) 963-4410 x 260
Location: US/Pacific
IRC: mage2k






В списке pgsql-sql по дате отправления:

Предыдущее
От: "Harold A. Giménez Ch."
Дата:
Сообщение: Re: pg_dump more than one table in one command?
Следующее
От: "Pavel Stehule"
Дата:
Сообщение: Re: Array from INSERT .. RETURNING in plpgsql?