Re: Function parameter type precision modifiers ignored.

Поиск
Список
Период
Сортировка
Искать
От
Tom Lane
Тема
Re: Function parameter type precision modifiers ignored.
Дата
Msg-id
4295.1423259824@sss.pgh.pa.us
Ответ на
Список
Дерево обсуждения
Function parameter type precision modifiers ignored. Mark Simonetti <marks@opalsoftware.co.uk>
Re: Function parameter type precision modifiers ignored. Tom Lane <tgl@sss.pgh.pa.us>
Re: Function parameter type precision modifiers ignored. David G Johnston <david.g.johnston@gmail.com>
Re: Function parameter type precision modifiers ignored. Tom Lane <tgl@sss.pgh.pa.us>
Mark Simonetti  writes:
> I don't know if this is a bug as such, but the behaviour certainly 
> confused me for a while : -

> Given the following PostgreSQL functions:

> CREATE OR REPLACE FUNCTION fn_dtm (
>      dtm timestamptz(0))
> RETURNS void AS $$
> BEGIN
>      RAISE NOTICE 'fn: %, %', dtm, dtm::timestamptz(0);
> END;
> $$ LANGUAGE plpgsql;

> CREATE OR REPLACE FUNCTION fn_num (
>      num numeric(5, 2))
> RETURNS void AS $$
> BEGIN
>      RAISE NOTICE 'num: %, %', num, num::numeric(5, 2);
> END;
> $$ LANGUAGE plpgsql;

> Would you expect the output of these functions to show the result as per 
> the type declared in the function parameter?

Attributes applied to function parameter types --- or result types for
that matter --- are entirely ignored by Postgres; only the base type
matters.  This is documented.

There's been some talk of rejecting syntax like the above, because we
get bug reports like this once or twice a year, so obviously a lot of
people are confused about what happens.

The odds of actually enforcing such typmods anytime in the near future
are not distinguishable from zero, but we could make CREATE FUNCTION
throw an error.

			regards, tom lane
В списке pgsql-bugs по дате отправления
От: Mark Simonetti
Дата:
От: David G Johnston
Дата:
FAQ