Re: store multiple rows with the SELECT INTO statement

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: store multiple rows with the SELECT INTO statement
Дата
Msg-id CAFj8pRD24r=o0U-vNi3m=ycc5JqfeSmAA=Qhfci+dXwZNyGvDg@mail.gmail.com
обсуждение исходный текст
Ответ на store multiple rows with the SELECT INTO statement  ("Janek Sendrowski" <janek12@web.de>)
Ответы Re: store multiple rows with the SELECT INTO statement  (Kevin Grittner <kgrittn@ymail.com>)
Список pgsql-general
Hello

PostgreSQL doesn't support a table variables, but you can use a arrays.

postgres=# create table foo2(a int, b int);
CREATE TABLE
postgres=# insert into foo2 select i, i+1 from generate_series(1,4) g(i);
INSERT 0 4
postgres=# select * from foo2;
 a | b
---+---
 1 | 2
 2 | 3
 3 | 4
 4 | 5
(4 rows)

postgres=# select array(select row(a,b) from foo2);
             ?column?             
-----------------------------------
 {"(1,2)","(2,3)","(3,4)","(4,5)"}
(1 row)
                                                             ^
postgres=# select * from unnest(array(select row(a,b) from foo2)) as (a int, b int);
 a | b
---+---
 1 | 2
 2 | 3
 3 | 4
 4 | 5
(4 rows)

or in plpgsql

postgres=# do $$
declare
  a foo2[] = array(select row(a,b) from foo2);
  r record;
begin
  for r in select * from unnest(a)
  loop
    raise notice '% %', r.a, r.b;
  end loop;
end;
$$;
NOTICE:  1 2
NOTICE:  2 3
NOTICE:  3 4
NOTICE:  4 5
DO


Regards

Pavel


2013/9/2 Janek Sendrowski <janek12@web.de>
Hi,
 
Why is it only possible to store one row by a query which returns multiple rows using the SELECT INTO statement.
and
How can I do a Query on a record varialbe, somehow like this:
SELECT * FROM v_rec
 
Janek Sendrowski

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: My Experiment of PG crash when dealing with huge amount of data
Следующее
От: Gianni Ceccarelli
Дата:
Сообщение: Re: SSI and predicate locks - a non-trivial use case