Which casts should be implicit

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Which casts should be implicit
Date: 2002-07-25 20:56:02
Message-ID: Pine.LNX.4.44.0207222311240.1144-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

From looking at the set of implicit or not casts, I think there are two
major issues to discuss:

1. Should truncating/rounding casts be implicit? (e.g., float4 -> int4)

I think there's a good argument for "no", but for some reason SQL99 says
"yes", at least for the family of numerical types.

2. Should casts from non-character types to text be implicit? (e.g., date
-> text)

I think this should be "no", for the same reason that the other direction
is already disallowed. It's just sloppy programming.

I also have a few individual cases that look worthy of consideration:

abstime <-> int4: I think these should not be implicit because they
represent different "kinds" of data. (These are binary compatible casts,
so changing them to not implicit probably won't have any effect. I'd have
to check this.)

date -> timestamp[tz]: I'm suspicious of this one, but it's hard to
explain. The definition to fill in the time component with zeros is
reasonable, but it's not the same thing as casting integers to floats
because dates really represent a time span of 24 hours and timestamps an
indivisible point in time. I suggest making this non-implicit, for
conformance with SQL and for general consistency between the date/time
types.

time -> interval: I'm not even sure this cast should exist at all.
Proper arithmetic would be IntervalValue = TimeValue - TIME 'midnight'.
At least make it non-implicit.

timestamp -> abstime: This can be implicit AFAICS.

--
Peter Eisentraut peter_e(at)gmx(dot)net

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2002-07-25 20:56:56 Re: regression in CVS HEAD
Previous Message Peter Eisentraut 2002-07-25 20:55:21 SET LOCAL again