Comments on: Handling NULL Values in PostgreSQL https://www.percona.com/blog/handling-null-values-in-postgresql/ Thu, 14 Dec 2023 00:54:59 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Sandor https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10972650 Tue, 25 Aug 2020 11:12:40 +0000 https://www.percona.com/blog/?p=65620#comment-10972650 Nice article. It’s also interesting to note that NULL values are not regarded in unique indices. So, while a duplicate non-NULL value is not allowed in a column that has a unique index on it, more than one NULL value *is* allowed. I’m not sure if this behavior is consistent across all major DMBSs but I suspect so.

]]>
By: Ibrar Ahmed https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10972000 Fri, 27 Mar 2020 13:58:07 +0000 https://www.percona.com/blog/?p=65620#comment-10972000 Yes, this is for some specified users who comes from different languages and try to learn SQL’s NULL.

]]>
By: Ibrar Ahmed https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971999 Fri, 27 Mar 2020 13:56:47 +0000 https://www.percona.com/blog/?p=65620#comment-10971999 Yes, we should hope to have data in all column 🙂

]]>
By: Leonardo Erpi https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971998 Fri, 27 Mar 2020 13:54:57 +0000 https://www.percona.com/blog/?p=65620#comment-10971998 NULL is not always good

]]>
By: cyberjots https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971997 Fri, 27 Mar 2020 13:40:17 +0000 https://www.percona.com/blog/?p=65620#comment-10971997 @Ibrar I guess the article is targeting a specific audience that seem to have a niche gap in their knowledge. When looked at from that point of view, a decent write up with good relevant examples.

Also, Federico’s article goes nicely with it. Thanks for the reminder @Federico.

]]>
By: Federico Razzoli https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971906 Sat, 07 Mar 2020 18:52:22 +0000 https://www.percona.com/blog/?p=65620#comment-10971906 @Ibrar Ahmed, on that part I agree. I find most of your article good and useful, and I’m sorry for not stressing this in my first comment. It’s good to explain developers that SQL NULL is not what they could expect if they are familiar with C or Java.

The sentence I disagree with is “In PostgreSQL, NULL means no value”. I agree that this is PostgreSQL intention (because this is what SQL standard says), but in practice all DBMSs I know treat it too inconsistently.

]]>
By: Ibrar Ahmed https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971905 Sat, 07 Mar 2020 16:52:19 +0000 https://www.percona.com/blog/?p=65620#comment-10971905 @Federico Razzoli, agreed, I just explained very basic difference of NULL in normal programming language and SQL.

]]>
By: Ibrar Ahmed https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971904 Sat, 07 Mar 2020 16:50:47 +0000 https://www.percona.com/blog/?p=65620#comment-10971904 @Michael I don’t disagree with you, but I just wrote this article for the people who has some programming experience in some language and try to write some SQL queries. I am comparing NULL in C/Java and SQL because name NULL is same but concept is 100% different. I met many people who does not know the basic concept of NULL in SQL. Secondly I really don’t want to go in very detail in user level blog, hope you understand.

]]>
By: Michael Darrin Chaney, Sr https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971903 Sat, 07 Mar 2020 16:20:00 +0000 https://www.percona.com/blog/?p=65620#comment-10971903 Every so often a cringy article like this comes out from someone who just found the word NULL in a few different places and went about trying to determine why the same word seemingly means different things.

First, you’re comparing an RDBMS engine (PostgreSQL) to programming languages (C & Java). That doesn’t even make sense. These are not the same thing.

Second, you need to understand it in the historical context. In C, NULL is 0. Why? In Unix systems, the first page of memory (which includes address 0) is typically set as inaccessible to a process. When pointers are initialized to 0, they point to this inaccessible piece of memory. This is one of the best ways to catch an uninitialized pointer, as using it will result in your program crashing immediately. So the uninitialized pointer is a null pointer. We don’t use NULL in other contexts – we just use 0. I wouldn’t put “for (x=NULL; …”. There’s a reason we have this, and it’s not to make typing “0” more difficult.

Third, your database examples are surprisingly good given the rest of this, but you missed one of the qualities of NULL values that is useful. They aren’t used in aggregate functions. For instance, taking the students_mark example, “select count(marks) from students_mark” will give you “2”, and “select average(marks) from students_mark” will give you “4.5”. In a database context, NULL means “missing or unknown”. Unfortunately, those are different concepts and you have to use your programming to make up for it.

Please also see the remarks from Federico Razzoli.

I would also add info about “null” in javascript.

]]>
By: Federico Razzoli https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971893 Thu, 05 Mar 2020 20:16:36 +0000 https://www.percona.com/blog/?p=65620#comment-10971893 Good article, but I dissent on one part: I believe that SQL NULL meaning is unclear, and depends on the context.
I explained my point in an article last year:
https://federico-razzoli.com/what-does-null-mean-in-sql

To sum up, my view is that some earlier versions of relational algebra defined two markers (I-marker and A-marker) that defined, respectively, an absent value and an unknown value. SQL standard merged these idea into a single NULL marker in an inconsistent way. The result is that, in practice, sometimes NULLs semantics only make sense if it means absent, sometimes they make sense if it means unknown, and sometimes they don’t make sense in both cases.

]]>
By: Ibrar Ahmed https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971892 Thu, 05 Mar 2020 15:37:11 +0000 https://www.percona.com/blog/?p=65620#comment-10971892 PostgreSQL is “following” the SQL standard, but NULL is definitely different in other Language like C and Java. This is specifically for those who have programming background and try to write SQL queries.

]]>
By: Nikolay Samokhvalov (@postgresmen) https://www.percona.com/blog/handling-null-values-in-postgresql/#comment-10971891 Thu, 05 Mar 2020 15:23:33 +0000 https://www.percona.com/blog/?p=65620#comment-10971891 > Especially in databases (PostgreSQL), NULL has some different concepts, so be careful when writing queries involving NULL.

In what databases?

NULL meaning is dictated by SQL standard, and Postgres follows it.

It would be interesting to see if some databases treat it differently compared to the standard.

]]>