Re: TODO: Fix CREATE CAST on DOMAINs

From: Mark Dilger <pgsql(at)markdilger(dot)com>
To: Mark Dilger <pgsql(at)markdilger(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: TODO: Fix CREATE CAST on DOMAINs
Date: 2006-09-20 17:26:55
Message-ID: 451179DF.1010608@markdilger.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Mark Dilger wrote:
> Casts from int2 -> int4, int2 -> int8, and int4 -> int8 would all be
> SAFE, I think, because they are not lossy. But perhaps I have not
> thought enough about this and these should be IMPLICIT rather than SAFE.

I have thought about this some more. I think these are indeed SAFE. The
distinction between SAFE and IMPLICIT should not, I think, be whether the
storage type is identical, but rather whether there is any possible loss of
precision, range, accuracy, etc., or whether there is any change in the
fundamental interpretation of the data when cast from the source to destination
type.

The built-in cast from int2 -> int4, which is currently IMPLICIT, cannot lose
any information, nor can it cause the data to be interpreted differently.
Therefore it is SAFE.

The built-in cast from int8 -> float8 is currently marked as IMPLICIT, but since
a large integer value which is cast in this fashion might be somewhat altered,
it is not SAFE. It is also interpreted differently, since floating point
numbers are typically interpreted as approximations, whereas integers are
interpreted as exact. (Hence the tendency to compare integers for equality, but
not floats.)

Can anyone think of examples where chaining together SAFE casts would cause
problems, using the guidelines for what is SAFE outlined above?

mark

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2006-09-20 17:31:46 Re: TODO: Fix CREATE CAST on DOMAINs
Previous Message Gregory Stark 2006-09-20 17:24:34 Re: Release Notes: Major Changes in 8.2