Re: Blank, nullable date column rejected by psql

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Blank, nullable date column rejected by psql
Date: 2019-02-12 08:20:03
Message-ID: 7ad1d0b443c12a1a6ea11606221b7201e933148f.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rich Shepard wrote:
> Now I know to replace no dates with null I'll do so but I'm curious why this
> is needed.

NULL is a special "unknown" value in SQL. You can use it for all
data types to signal that a value is unknown or not available.

If you insert a string into a "date" column, PostgreSQL will try
to convert the string to a date with the type input function.
The type input function fails on an empty string, since it cannot
parse it into a valid "date" value.
This also applies to the empty string.

But NULL is always a possible value (unless the column definition
excludes it).

Used properly, NULL solves many problems.

Imagine you want to know how long in the future the date is.
If you use "next_contact - current_timestamp", and "next_contact"
is NULL, then the result of the operation will automatically be
NULL (unknown) as well. That is much better than any "zero" value
which would lead to an undesired result.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Niels Jespersen 2019-02-12 09:34:08 SV: Implementing pgaudit extension on Microsoft Windows
Previous Message Pavel Stehule 2019-02-12 08:00:51 Re: Implementing pgaudit extension on Microsoft Windows