Skip site navigation (1) Skip section navigation (2)

Re: SQL question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>, Carolyn Lu Wong <carolyn(at)kss(dot)net(dot)au>, pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL question
Date: 2000-07-17 07:03:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> At 02:26 17/07/00 -0400, Tom Lane wrote:
>> Well before my time, I guess --- as long as I've been paying attention,
>> the function manager's approach was to call the routine first and *then*
>> insert a NULL result ... if the routine hadn't crashed first.  That's
>> about as braindead a choice as I can think of, but that's what it did.

> Out of curiosity, what does it do now? 

As of current sources there is a distinction between "strict" and
"non-strict" functions.  A strict function must return NULL if any
input is NULL, therefore the function manager won't call it at all
if there is a NULL input value, but just assume the NULL result.
(Some other DBMSes have the same concept under different names,
like "NOT NULL CALL".)

A non-strict function is assumed to be able to take care of itself.
It gets called anyway and must check to see if any of its inputs
are NULL, then decide what it wants to do about it.

Both strict and nonstrict functions can return NULL if they wish,
though I've not seen many cases where a strict function would want to.

This is all predicated on a new function call interface that provides
an explicit isNull flag for each input, as well as an isNull flag for
the function result.  The real problem with the old code was that we
didn't have that, and there is no non-kluge workaround for not having
the information.

If I understand Thomas' remarks correctly, at one time in the past
the function-call code operated as though all functions were strict.
I suppose that foundered on the little problem that certain operations
like IS NULL and IS NOT NULL *must* be non-strict.  So someone changed
it to the opposite convention, but didn't follow through to the bitter
end: there has to be an explicit null flag for *each* argument, as
well as a clean way for the function to say whether it is returning
a null or not.

Defaulting to non-strict also created a ton of potential crash sites
in routines that couldn't cope with null-pointer inputs.  We've been
gradually "fixing" those by adding explicit tests for nulls, but it's
always been a stopgap solution IMHO.  Now there's a better way.
99% of the built-in functions in the backend are "strict" and so
will no longer need special checks to defend against null inputs,
because they'll never see 'em again.

			regards, tom lane

In response to

pgsql-sql by date

Next:From: Gary J. FarmerDate: 2000-07-17 22:12:54
Subject: RE: Select by priority
Previous:From: Philip WarnerDate: 2000-07-17 06:31:29
Subject: Re: SQL question

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group