help defining a stored procedure that returns a record or an arrayusing SELECT INTO

Поиск
Список
Период
Сортировка
От Luca Ferrari
Тема help defining a stored procedure that returns a record or an arrayusing SELECT INTO
Дата
Msg-id CAKoxK+4DHd-axJUW3tyeXuRdoBO=xLE83ajaCCeR5uqDuoWshw@mail.gmail.com
обсуждение исходный текст
Ответы Re: help defining a stored procedure that returns a record or anarray using SELECT INTO  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-sql
Hi all,
this may sound trivial, but I'm not able to create a simple function
that returns either an array or a record.
For instance, the following:

CREATE TYPE t_agg AS (
  t_count   int,
  t_sum int
);

CREATE OR REPLACE FUNCTION f_compute()
RETURNS t_agg
AS
$BODY$
  DECLARE
    tot t_agg%rowtype;
  BEGIN
    SELECT  count(id)
            , sum( f_value )
    INTO STRICT tot
    FROM my_table;

    RETURN tot;

  END
$BODY$
LANGUAGE plpgsql;


provides a tuple of t_agg with a simple count and sum.

1) is it possible to change the return value to int[] (and
consequently tot variable) using the SELECT INTO statement?
2) if I change the return type to record (and consequently the tot
variable), how should I name columns so that the parse knows what
tuple it is returning still using the SELECT INTO?

Thanks,
Luca


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

Предыдущее
От: Olivier Leprêtre
Дата:
Сообщение: search inside partitions
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: help defining a stored procedure that returns a record or anarray using SELECT INTO