error handling in cast functions for user defined types

Started by Don Yalmost 20 years ago3 messagesgeneral
Jump to latest
#1Don Y
pgsql@DakotaCom.Net

Hi,

I'm writing a set of casts to/from various user defined
types. As is unexpected, there are cases where one
data type doesn't neatly map to another (for certain
values). In these cases I emit an INVALID_PARAMETER_VALUE
or OUT_OF_RANGE error -- depending on the situation.

But, should I also PG_RETURN_NULL()? I note the
cast of int4's to int2's signal similar errors -- *but*
returns "(int2) value".

Is the return value just *ignored* when the error is
signaled?

Thanks!
--don

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Don Y (#1)
Re: error handling in cast functions for user defined types

Don Y <pgsql@DakotaCom.Net> writes:

I'm writing a set of casts to/from various user defined
types. As is unexpected, there are cases where one
data type doesn't neatly map to another (for certain
values). In these cases I emit an INVALID_PARAMETER_VALUE
or OUT_OF_RANGE error -- depending on the situation.

But, should I also PG_RETURN_NULL()?

elog(ERROR) doesn't return to your function --- think of it as being
like exit(). So it's pointless to code anything after it.

regards, tom lane

#3Don Y
pgsql@DakotaCom.Net
In reply to: Tom Lane (#2)
Re: error handling in cast functions for user defined types

Tom Lane wrote:

Don Y <pgsql@DakotaCom.Net> writes:

I'm writing a set of casts to/from various user defined
types. As is unexpected, there are cases where one
data type doesn't neatly map to another (for certain
values). In these cases I emit an INVALID_PARAMETER_VALUE
or OUT_OF_RANGE error -- depending on the situation.

But, should I also PG_RETURN_NULL()?

elog(ERROR) doesn't return to your function --- think of it as being
like exit(). So it's pointless to code anything after it.

Ah, OK. "/* NOT REACHED */"

Thanks!
--don