Обсуждение: Are scalar type's in/out functions implicitly STRICT?
So, I create some new scalar type and I don't declare its in/out functions as STRICT. But PostgreSQL copes with them such as they would be STRICT - they never get the NULL value. And this is not documented, AFAIK. Have I missed something or is it a some hard well-known etc. fact? Thanks in advance.
Denis Zaitsev <zzz@cd-club.ru> writes: > So, I create some new scalar type and I don't declare its in/out > functions as STRICT. But PostgreSQL copes with them such as they > would be STRICT - they never get the NULL value. This is likely true in many places --- for example, COPY has a shortcut because it wants to substitute \N for nulls. It would not be a bright idea to assume that it's true in every place and forevermore. In general, if you have a C function and don't want to be bothered with explicit PG_ISNULL testing, you'd better mark it STRICT. An example of an easy way to crash an I/O function without such guards is to invoke it explicitly: regression=# select textin(null::cstring);textin -------- (1 row) regression=# select textout(null::text);textout --------- (1 row) regards, tom lane
On Fri, Feb 28, 2003 at 05:45:44 +0500, Denis Zaitsev <zzz@cd-club.ru> wrote: > So, I create some new scalar type and I don't declare its in/out > functions as STRICT. But PostgreSQL copes with them such as they > would be STRICT - they never get the NULL value. And this is not > documented, AFAIK. Have I missed something or is it a some hard > well-known etc. fact? Thanks in advance. Are you using the version one calling sequence? The version zero method doesn't have a way handle nulls other than by declaring the function strict.
On Thu, Feb 27, 2003 at 09:44:37PM -0500, Tom Lane wrote: > Denis Zaitsev <zzz@cd-club.ru> writes: > > So, I create some new scalar type and I don't declare its in/out > > functions as STRICT. But PostgreSQL copes with them such as they > > would be STRICT - they never get the NULL value. > > This is likely true in many places --- for example, COPY has a shortcut > because it wants to substitute \N for nulls. It would not be a bright > idea to assume that it's true in every place and forevermore. In > general, if you have a C function and don't want to be bothered with > explicit PG_ISNULL testing, you'd better mark it STRICT. > Ok, thanks.
On Thu, Feb 27, 2003 at 09:24:44PM -0600, Bruno Wolff III wrote: > On Fri, Feb 28, 2003 at 05:45:44 +0500, > Denis Zaitsev <zzz@cd-club.ru> wrote: > > So, I create some new scalar type and I don't declare its in/out > > functions as STRICT. But PostgreSQL copes with them such as they > > would be STRICT - they never get the NULL value. And this is not > > documented, AFAIK. Have I missed something or is it a some hard > > well-known etc. fact? Thanks in advance. > > Are you using the version one calling sequence? Yes, I am - v1. > The version zero method doesn't have a way handle nulls other than by > declaring the function strict. > Hmm, examples/docs show such a way for v0...