Re: appending items to record variable

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: appending items to record variable
Дата
Msg-id AANLkTilsnClpOzTJ6E091LKuS1RjkDgMoxqyPzwadQEN@mail.gmail.com
обсуждение исходный текст
Ответ на appending items to record variable  (x y <charliesen@googlemail.com>)
Список pgsql-general
On Fri, May 14, 2010 at 9:12 AM, x y <charliesen@googlemail.com> wrote:
> Hi all
>
> In plpgsql, is there a way to append rows to a record variable?
>
> Each time a query like
> SELECT mycolumn INTO myrecordvariable FROM ...
> is executed, myrecordvariable seems to be reseted and previous entries are lost.
>
> What I want to do is collect values throughout several conditionals
> and then (when the collection is finished) continue processing  these
> values - all in a single function.
>
> An array does not suite because searching is to slow and creating a
> temporary table is not what I want either..
> Or are there any other means to collect items into a searchable list of values?

A record variable is scalar by design -- it's only supposed to hold a
single row.  Arrays are the way to do what you want as long as the
number of records is relatively small.  Temp tables can be searched,
but they are also brute force unless you index the temp table, and
there are other annoying things about them.

Probably you can fix your problem by using an array and re-thinking
how you express that array in later queries:

foos = foo[];

with (f as select unnext(_foos))
select * from f join foo using (foo_id) ...

Also you probably want to avoid stacking the array iteratively.  In
fact, avoid iterative processing wherever possible.

merlin

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

Предыдущее
От: Vick Khera
Дата:
Сообщение: Re: Pulling data from a constraint def
Следующее
От: Vick Khera
Дата:
Сообщение: Re: Poor query performance on one of two "like" databases in production.