Обсуждение: Cast possible only throught a function

Поиск
Список
Период
Сортировка

Cast possible only throught a function

От
"Mendola Gaetano"
Дата:
Hi all,
running on Postgres 7.3.3
I seen that cast a integer to an intervall is not permitted

select 0::interval;    <- give error

but

select 0::text::interval;   <- works fine

but I notice that the following function return correctly
doing the integer -> interval cast in one "shot":

create or replace function foo()
returns interval as '
declare
begin
 return 0;
end;
' language 'plpgsql';



this implicit cast could not be source of issue ?


Gaetano

Re: Cast possible only throught a function

От
Tom Lane
Дата:
"Mendola Gaetano" <mendola@bigfoot.com> writes:
> but I notice that the following function return correctly
> doing the integer -> interval cast in one "shot":

What plpgsql is doing is roughly comparable to

regression=# select '0'::interval;
 interval
----------
 00:00:00
(1 row)

This is not the same as a SQL type conversion --- that works only when a
cast function is defined in pg_cast.

plpgsql is pretty lax about datatype considerations.  It is willing to
try to convert anything to anything else by running the first type's
output procedure (to get text) and then the second type's input
procedure.  In straight SQL you'd have to specify a cast to text to
get the equivalent behavior.

            regards, tom lane