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

Поиск
Список
Период
Сортировка
От John Lumby
Тема Re: NULL as a (pseudo-)value not described?
Дата
Msg-id BAY175-W1AD536CBBA8DF14312ECDA3CD0@phx.gbl
обсуждение исходный текст
Ответ на Re: NULL as a (pseudo-)value not described?  (David Johnston <david.g.johnston@gmail.com>)
Список pgsql-docs

________________________________
> Date: Thu, 11 Sep 2014 22:08:05 -0400
> Subject: Re: [DOCS] NULL as a (pseudo-)value not described?
> From: david.g.johnston@gmail.com
> To: johnlumby@hotmail.com
> CC: pgsql-docs@postgresql.org
>
>
>
> On Thu, Sep 11, 2014 at 9:24 PM, johnlumby
> <johnlumby@hotmail.com<mailto:johnlumby@hotmail.com>> wrote:
> On 09/11/14 10:03, David Johnston wrote:
> On Thu, Sep 11, 2014 at 9:24 AM, John Lumby
> <johnlumby@hotmail.com<mailto:johnlumby@hotmail.com>> wrote:
> ​As I mentioned before the fact that null is a literal/constant is
> ...
> ​OK - pseudo-constant then; it can be used in any place a normal
> constant can be used for those situations where you don't have a
> well-defined value to put there.​
>
> 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.

Not to harp on this,  but although "trying" it in the sense of
 typing it in and seeing if some error occurs is easy,
verifying that it produces the expected result in the database
is far from easy IF the person doing it cannot find
any semantic definition of a null value,  e.g. the various
tricky "unknown" rules etc.

>
> 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.
>
> ...
>
> ​User documentation does not want to copy from standards, or in many
> cases, source code.  The person writing said documentation should be
> informed by those sources and then write something targeted for the
> typical user.
>
> You entire paragraph boils down to: NULL can be used like a constant
> but when compared with itself, or other constants, results in the third
> logical state - unknown.
>
> ​It can be declared as a default:   CREATE TABLE test ( col varchar
> NULL DEFAULT NULL );
>
> And its use in an expression is not limited any more than any other
> "true constant"
>
> More of a semantic but you can attempt to insert NULL into a column
> having a NOT NULL constraint - it will just cause an error.  Much like
> you can attempt to insert -20 into a column with a constraint CHECK(col
> >= 0)
>
>
>
> My rough idea at the moment is to introduce a section in "Tutorial: The
> SQL Language" chapter, subsequent to "Joins Between Tables", and
> summarize and cross-reference to other sections the concept and use of
> NULL.  The three prior sections (Rows, Queries, Joins) all have NULL
> implications that are not covered in those chapters explicitly and
> adding it to all three doesn't feel right.  A separate encapsulating
> chapter seems better and lets the reader focus on those topics without
> the immediate distraction of NULL complicating things. This would be
> the "reference section" for the topic.  If you think of the topic as
> being a pre-requisite then the tutorial does make some sense - and when
> I devised the above I didn't really process that this was "tutorial"
> material...consideration for another time.
>
> In "SQL Syntax" I would cover the topic again under "constants" -
> probably calling them pseudo-constant (inspired from the above
> discussion).
>
> I'm uncertain on whether or how to cover them within the "Data Types"
> chapter but feel like it should be mentioned there as well.
>
> David J.
>

Yes,   I agree,   that all sounds good,
     and also thanks for correcting factual errors in my version.

I have two comments,  one of which I think you may have already addressed:

1 .   would be good if the documentation distinguishes
    between two slightly different points:
     .    the semantic meaning of a null value
     .   valid syntactic uses of the token NULL

2.    I suggest including somewhere explicit examples of
       setting a column value to NULL
      a)  in a VALUES clause of INSERT
      b)  in a SET clause of UPDATE

В списке pgsql-docs по дате отправления:

Предыдущее
От: David Johnston
Дата:
Сообщение: Re: NULL as a (pseudo-)value not described?
Следующее
От: "Laurence Parry"
Дата:
Сообщение: Huge pages section needs to describe hugetlb_shm_group, memlock limit