Re: NULL as a (pseudo-)value not described?

From: johnlumby <johnlumby(at)hotmail(dot)com>
To: David Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-docs(at)postgresql(dot)org" <pgsql-docs(at)postgresql(dot)org>
Subject: Re: NULL as a (pseudo-)value not described?
Date: 2014-09-12 01:24:26
Message-ID: BLU436-SMTP48DBEDDC7500C8C912BAA3A3CD0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 09/11/14 10:03, David Johnston wrote:
> John, please respond to the list next time.

Sorry, I was not sure if I understood what you were saying.
Now I do ...

>
>
> On Thu, Sep 11, 2014 at 9:24 AM, John Lumby <johnlumby(at)hotmail(dot)com
> <mailto:johnlumby(at)hotmail(dot)com>> wrote:
>
> Thanks David ... but ... (below)
>
> ----------------------------------------
> > Date: Wed, 10 Sep 2014 18:20:00 -0700
> > From: david(dot)g(dot)johnston(at)gmail(dot)com <mailto:david(dot)g(dot)johnston(at)gmail(dot)com>
> > To: pgsql-docs(at)postgresql(dot)org <mailto:pgsql-docs(at)postgresql(dot)org>
> > Subject: Re: [DOCS] NULL as a (pseudo-)value not described?
> >
> > johnlumby wrote
> >> As far as I can tell,
> >> the un-value NULL is not described anywhere in the doc
> >> as being something that can be assigned to a column.
> >>
> >> E.g. :
> >> . not listed as a constant (well that's reasonable as it
> isn't)
> >> . not listed as an expression (is NULL an expression?)
> >> . not explicitly listed under the INSERT and UPDATE commands
> >> as a valid syntactic unit as an alternative to an
> expression
> >> (If it is not an expression)
> >>
> >> I do see it listed as a valid keyword but there is no
> description there.
> >>
> >> To put it another way, the following syntax is apparently not
> permitted
> >> :
> >> UPDATE my_nullable_table SET nullable_col = NULL;
> >>
> >> (I am not referring to other null-related constructs such as IS
> NULL,
> >> IFNULL etc)
> >>
> >> I have to assume I'm missing something?
> >> Or is it that NULL is so, well, null, that it cannot be
> described?
>
> >
> > http://www.postgresql.org/docs/9.4/static/ddl-default.html
> >
> > To your point: null is a constant/literal as defined in
> >
> >
> http://www.postgresql.org/docs/9.4/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL
>
> Well I have searched that page from top to bottom
> and nowhere do I see such a statement. There are many mentions
> of the word "NULL" and "null" but as far as I can tell none of these
> refer to to the use of the word as a substitute for a value
> such as occurs in a column assignment in an INSERT or UPDATE command.
>
> Can you please cut'n'paste the relevant text that you see that
> states this?
>
>
> ​As I mentioned before the fact that null is a literal/constant is
> assumed. My point here is that given that assumption the referenced
> section explains that "SET col = null" is valid. SET col =
> <expression>, <constants> are <expressions>, null is a valid
> <constant>, ergo SET col = null is valid.

Ah, ok. Well, I would say that NULL is not a constant,
since a constant has a well-defined value and can be used
to represent that value in any expression, neither of which
are true of NULL. However see my last para.

>
> The documentation does not describe all possible valid constants -
> though I admit given the special nature of NULL it probably should do
> so in this instance. The trick is avoiding adding comments pertaining
> to NULL all over the documentation (see below) and confusing the
> underlying normal non-null usage. Thus, right now, only when NULL
> behavior is important does it get addressed. SET col = NULL is no
> different then SET col = 'a string' so why make it seem like a
> special case by pointing out the "obvious"?
>
> Even if people are not positive simply trying what you wrote is easy
> and in the absence of any error it would become obvious that NULL is
> valid in UPDATE/SET.
>
> The larger problem is people thinking "NULL = NULL" returns true or
> "NULL = 'some other literal'" returns FALSE: i.e., that NULL is never
> special but is just another literal.

Actually I have seen mailings where someone is asking how to set a
column value to NULL
so I'd say it is not obvious. A reference manual should preferably
avoid
assuming anything about what it is documenting.

>
>
> >
> > and so can appear in the defined expression area and so your
> example is
> > explicitly allowed.
> >
> >
> http://www.postgresql.org/docs/9.4/static/bookindex.html#AEN167062
> (under
> > "N")
>
> Likewise -- 8 instances of the nullness concept,
> none of which refer to to the use of the word as a substitute for
> a value
>
> such as occurs in a column assignment in an INSERT or UPDATE command.
>
>
> ​Fair enough...my response was somewhat unorganized.​ Again, this
> supports the theory that it is assumed people know what null is and
> simply need to see how PostgreSQL specifically treats it.
>
> >
> > Pseudo-type has a specific meaning is PostgreSQL which null does
> not conform
> > to.
> >
> > Having brought this to attention why did you go looking for it
> and where, in
> > order, did you look?
>
>
> ​ I've already agreed the documentation could be improved - but since
> you are the one who brought this up it would be helpful to get your
> thoughts on how best to do that. Most everyone on this list
> intimately understands how NULL works so while we can write accurate
> documentation it is more difficult to write/organize the documentation
> for the purposes of learning. IOW, It would be nice to get to know
> the target audience.

Well, I would assume that one or other of the SQL ANSI standards
documents NULL
and (provided postgresql confirms to that standard) we can simply copy
or rephrase
that text. However, I personally am not a standards expert, and after
a short
and futile search on on the web I can't find any accessible html/pdf
format of any SQL ANSI standard.
I assume someone more knowledgeable on standards could find it.
But if I had to take a shot at it, I would add a description of NULL at
the bottom of section 4.2
following the text :
"In addition to this list, there are a number of constructs that can
be classified
as an expression but do not follow any general syntax rules.
These generally have the semantics of a function or operator and
are explained
in the appropriate location in Chapter 9. An example is the IS
NULL clause."

something along these lines :

<start addition>
Another example is the NULL token. This is not a value but can
be included in certain commands
where a value can be assigned to a column, such as INSERT (the
VALUES clause)
and UPDATE (the SET clause), in the same position as a value
would be placed,
provided the column is not defined as NOT NULL. Its meaning is
"no value".
It is not equal to any other value, and not unequal to any other
value,
and not equal to another NULL, and not unequal to another NULL.
NULL may not be stated as an explicit default value for a column,
but if no default value is defined for a column which is not
defined as NOT NULL,
then its default value is NULL. In this case, NULL has the
sense of "not set".
<is the next true? I am not somewhere to verify ...?>
It cannot be used in an expression other than when it occurs
alone without any associated operator or function.
</is the above true? I am not somewhere to verify ...?>
</end addition>

>
> David J.
>
>
> ​

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message David Johnston 2014-09-12 02:08:05 Re: NULL as a (pseudo-)value not described?
Previous Message David Johnston 2014-09-11 14:03:00 Re: NULL as a (pseudo-)value not described?