functions behaviours

Поиск
Список
Период
Сортировка
От ycrux@club-internet.fr
Тема functions behaviours
Дата
Msg-id mnet1.1144155739.9536.ycrux@club-internet.fr
обсуждение исходный текст
Ответы Re: functions behaviours  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Список pgsql-general
Hi All!

I'm wondering if there is an elegant way to add simple behaviours to stored Postgres functions.

1. First, what I want to get here is a function which orders their results columns in ASC at one time and in DESC next
timeit is called. Something like that: 

CREATE FUNCTION sort_swap(integer) RETURNS SETOF atype AS '

   sort_type ALIAS FOR $1;
   row atype;

   IF sort_type = 'ASC' THEN

    FOR row IN SELECT column1 ASC, column2, column3 FROM table
               ORDER BY column1 ASC, column2, column3
      LOOP
         RETURN NEXT row;
      END LOOP;

   ELSE

     FOR row IN SELECT column1 ASC, column2, column3 FROM table
               ORDER BY column1 DESC, column2, column3
      LOOP
         RETURN NEXT row;
      END LOOP;

   END IF;

    RETURN;
' LANGUAGE plpgsql;

What I want here is a function without the sort_type parameter.

2. Second, is it possible to give a function a parameter which correspond to a table name?

CREATE FUNCTION function_with_behaviours(integer) RETURNS SETOF atype AS '

   table_name ALIAS FOR $1;
   row atype;

      SELECT INTO row *  FROM table_name;

    RETURN row;
' LANGUAGE plpgsql;

In that case, how to dynamically adapt  atype  to the be table_name%ROWTYPE ?


Thanks in advance
Youn


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

Предыдущее
От: Ottavio Campana
Дата:
Сообщение: Re: database design questions
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: functions behaviours