Re: Function parameter type precision modifiers ignored. - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Function parameter type precision modifiers ignored.
Date
Msg-id 4295.1423259824@sss.pgh.pa.us
Whole thread Raw
In response to Function parameter type precision modifiers ignored.  (Mark Simonetti <marks@opalsoftware.co.uk>)
Responses Re: Function parameter type precision modifiers ignored.  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-bugs
Mark Simonetti <marks@opalsoftware.co.uk> 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 by date:

Previous
From: Mark Simonetti
Date:
Subject: Function parameter type precision modifiers ignored.
Next
From: David G Johnston
Date:
Subject: Re: Function parameter type precision modifiers ignored.