Re: How to check whether a data type can be cast to another
| От | Tom Lane | 
|---|---|
| Тема | Re: How to check whether a data type can be cast to another | 
| Дата | |
| Msg-id | 9888.1256306408@sss.pgh.pa.us обсуждение исходный текст  | 
		
| Ответ на | How to check whether a data type can be cast to another (Kareem Sedki <isiscreation@gmail.com>) | 
| Ответы | 
                	
            		Re: How to check whether a data type can be cast to another
            		
            		 | 
		
| Список | pgsql-general | 
Kareem Sedki <isiscreation@gmail.com> writes:
> I am trying to write a function that takes one source and one target
> data type identifiers, each as a '/text/' variable, as arguments and
> return true if the cast can be made, false otherwise.
I think this is fundamentally the wrong approach, because it ignores the
question of whether a specific value can be cast.  For example, there is
a cast from int4 to int2, but that doesn't mean that 999999::int2 will
succeed.  What I think you should do is just try the cast and catch any
error that occurs.
If you really want to try to do what you're saying, look into
parser/parse_coerce.c.  In particular, can_coerce_type() is the
authoritative answer.
            regards, tom lane
		
	В списке pgsql-general по дате отправления: