Re: TODO: Fix CREATE CAST on DOMAINs - Mailing list pgsql-hackers

From Mark Dilger
Subject Re: TODO: Fix CREATE CAST on DOMAINs
Date
Msg-id 451179DF.1010608@markdilger.com
Whole thread Raw
In response to Re: TODO: Fix CREATE CAST on DOMAINs  (Mark Dilger <pgsql@markdilger.com>)
Responses Re: TODO: Fix CREATE CAST on DOMAINs  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: TODO: Fix CREATE CAST on DOMAINs  (Martijn van Oosterhout <kleptog@svana.org>)
List 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
inthis 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


pgsql-hackers by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Release Notes: Major Changes in 8.2
Next
From: Tom Lane
Date:
Subject: Re: TODO: Fix CREATE CAST on DOMAINs