Re: function with different return type depending on parameter?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: function with different return type depending on parameter?
Дата
Msg-id 24654.1392218663@sss.pgh.pa.us
обсуждение исходный текст
Ответ на function with different return type depending on parameter?  (James Harper <james.harper@bendigoit.com.au>)
Ответы Re: function with different return type depending on parameter?  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
James Harper <james.harper@bendigoit.com.au> writes:
> is it possible to have a function that can return a different type
> depending on the parameters?

The data type of any expression (including a function call) has to be
determinable at parse time, so no you can't just randomly return a
run-time-determined data type.

However, have you looked at the "polymorphic functions" feature?
You can declare a function as returning the same data type that
one of its inputs has.  This seems to cover most of the cases
that are useful in practice.

http://www.postgresql.org/docs/9.3/static/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC
http://www.postgresql.org/docs/9.3/static/xfunc-sql.html#AEN52916

            regards, tom lane


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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: pgsql and asciidoc output
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: pgsql and asciidoc output