Re: polymorphic SQL functions has a problem with domains

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: polymorphic SQL functions has a problem with domains
Дата
Msg-id 1396453673324-5798356.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: polymorphic SQL functions has a problem with domains  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: polymorphic SQL functions has a problem with domains
Список pgsql-hackers
Tom Lane-2 wrote
> Pavel Stehule <

> pavel.stehule@

> > writes:
>> I was informed about impossibility to use a polymorphic functions
>> together
>> with domain types
> 
>> see
> 
>>  create domain xx as numeric(15);
> 
>> create or replace function g(anyelement, anyelement)
>> returns anyelement as
>> $$  select $1 + $2 $$
>> language sql immutable;
> 
>> postgres=# select g(1::xx, 2::xx);
>> ERROR:  return type mismatch in function declared to return xx
>> DETAIL:  Actual return type is numeric.
>> CONTEXT:  SQL function "g" during inlining
> 
> That example doesn't say you can't use polymorphic functions with domains.
> It says that this particular polymorphic function definition is wrong:
> it is not making sure its result is of the expected data type.  I don't
> recall right now whether SQL functions will apply an implicit cast on the
> result for you, but even if they do, an upcast from numeric to some domain
> over numeric wouldn't be implicit.

How would that be possible though?  Since any number of domains could be
defined over numeric as soon as the "+" operator causes the domain to be
lost there is no way to get it back manually - you cannot just make it
"SELECT ($1 + $2)::xx".

Does something like:

SELECT ($1 + $2)::$1%TYPE 

exist where you can explicitly cast to the type of the input argument?

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/polymorphic-SQL-functions-has-a-problem-with-domains-tp5798349p5798356.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.



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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: polymorphic SQL functions has a problem with domains
Следующее
От: Tom Lane
Дата:
Сообщение: Re: polymorphic SQL functions has a problem with domains