Re: BUG #1022: date calculation forces wrong type in function parameter and causes error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: bpatin(at)padecs(dot)riss(dot)net
Cc: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #1022: date calculation forces wrong type in function parameter and causes error
Date: 2003-12-19 23:33:04
Message-ID: 12659.1071876784@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> In Pg 7.3 and before, I have successfully used a function with a date parameter such as this simplified version:

Perhaps this worked in 7.2 and before, before we tightened the
implicit-casting rules. It does not work in 7.3.

> CREATE FUNCTION input_date(date) RETURNS INT AS 'SELECT 0;' LANGUAGE 'SQL';

> select input_date('now'::date+'5 years'::interval);

There is not and never has been a date + interval operator. In all
PG versions, the date constant would get coerced to timestamp or
timestamptz to be added to interval, and the result of the addition
would likewise be of type timestamp or timestamptz. The reason it
"worked" in old releases is that the result would be silently
down-converted to date to feed to the function. We no longer think it
a good idea to perform information-losing coercions silently.

If you are intent on having the old behavior you can fool with the
contents of the pg_cast table to make timestamp->date be an implicit
coercion. But I'd recommend fixing your code instead. Or create
a date-plus-interval operator that does what you want.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Lewis Foti 2003-12-19 23:47:32 Re: Jdbc connection pooling and PG 7.4 consistently fails
Previous Message Bruce Momjian 2003-12-19 23:32:31 Re: pg_service.conf ignores dbname parameter