Identifying casts

Started by Marc Munroover 18 years ago3 messagesgeneral
Jump to latest
#1Marc Munro
marc@bloodnok.com

Is there any way of identifying whether a cast was built-in or is
user-defined?

I am tempted to just assume that if the cast is to/from a user-defined
type or uses a user-defined function that it is user-defined. I suspect
though that a user could define a new cast on pre-defined types using a
pre-defined function.

__
Marc

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Marc Munro (#1)
Re: Identifying casts

Hello

you can use oid. When oid is greather than some constant, then cast is
custom. The constant is different on any postgresq versions.

You can get it on clean postgres with statement

select max(oid) from pg_cast;

Regards
Pavel Stehule

Show quoted text

On 07/12/2007, Marc Munro <marc@bloodnok.com> wrote:

Is there any way of identifying whether a cast was built-in or is
user-defined?

I am tempted to just assume that if the cast is to/from a user-defined
type or uses a user-defined function that it is user-defined. I suspect
though that a user could define a new cast on pre-defined types using a
pre-defined function.

__
Marc

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Marc Munro (#1)
Re: Identifying casts

Marc Munro <marc@bloodnok.com> writes:

Is there any way of identifying whether a cast was built-in or is
user-defined?

It's not easy. I'd suggest following the same heuristic pg_dump
does, which is that if any of the source type, target type, or
underlying function is considered user-defined, then the cast is too.

regards, tom lane