Re: How to check whether a data type can be cast to another

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kareem Sedki <isiscreation(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to check whether a data type can be cast to another
Date: 2009-10-23 15:24:33
Message-ID: 10963.1256311473@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kareem Sedki <isiscreation(at)gmail(dot)com> writes:
> The problem I faced is that the type 'any' is not permitted in
> procedural languages. If it were permitted, then we could have a
> function like is_castable( value ANY, target_type TEXT) and then we
> would catch exceptions if they are thrown.

ANYELEMENT maybe?

> Here is what we have, there is a field in which we should store
> different data types and another field in the same row to store the
> identifier of the original data type of the first field. The first field
> should be polymorphic.

Although actually I think you should stop right here and rethink what
you are doing. It sounds a whole lot to me like you are trying to build
an EAV store, and that seldom leads to anything good. It is much better
to spend the necessary effort up-front to work out a concrete
fully-typed schema for your database.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nim Li 2009-10-23 15:27:11 Question of using trigger's OLD in EXECUTE
Previous Message Kareem Sedki 2009-10-23 15:14:58 Re: How to check whether a data type can be cast to another