Re: Blank, nullable date column rejected by psql - Mailing list pgsql-general

From Laurenz Albe
Subject Re: Blank, nullable date column rejected by psql
Date
Msg-id 7ad1d0b443c12a1a6ea11606221b7201e933148f.camel@cybertec.at
Whole thread Raw
In response to Blank, nullable date column rejected by psql  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Blank, nullable date column rejected by psql  (Rich Shepard <rshepard@appl-ecosys.com>)
List 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



pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Implementing pgaudit extension on Microsoft Windows
Next
From: Niels Jespersen
Date:
Subject: SV: Implementing pgaudit extension on Microsoft Windows