Skip to content

Commit

Permalink
sql null
Browse files Browse the repository at this point in the history
  • Loading branch information
haunt98 committed Jan 11, 2025
1 parent 87cec26 commit 0c7cefa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
24 changes: 22 additions & 2 deletions docs/2022-07-31-sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ <h2 class="heading-element">Be careful with NULL</h2>
<span class="pl-k">FROM</span> table
<span class="pl-k">WHERE</span> (field_something IS <span class="pl-k">NULL</span> <span class="pl-k">OR</span> field_something <span class="pl-k">!=</span> <span class="pl-c1">1</span>)</pre>
</div>
<p>Need clarify why this happen? Idk :(</p>
<p>
Because <code>NULL</code> is not equal to anything, even
<code>NULL != NULL</code>, we only can check with <code>IS NULL</code> or
<code>IS NOT NULL</code>.
</p>
<div class="markdown-heading">
<h2 class="heading-element"><code>VARCHAR</code> or <code>TEXT</code></h2>
<a
Expand Down Expand Up @@ -516,9 +520,25 @@ <h2 class="heading-element">Thanks</h2>
<a
href="https://www.depesz.com/2024/12/01/sql-best-practices-dont-compare-count-with-0/"
rel="nofollow"
>SQL best practices – don’t compare count(*) with 0</a
>SQL best practices – don’t compare count with 0</a
>
</p>
</li>
<li>
<p>
<a
href="https://jirevwe.github.io/sql-nulls-are-weird.html"
rel="nofollow"
>SQL NULLs are Weird!</a
>
</p>
<ul>
<li>
<a href="https://www.sqlite.org/nulls.html" rel="nofollow"
>NULL Handling in SQLite Versus Other Database Engines</a
>
</li>
</ul>
</li>
</ul>

Expand Down
7 changes: 5 additions & 2 deletions posts/2022-07-31-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ FROM table
WHERE (field_something IS NULL OR field_something != 1)
```

Need clarify why this happen? Idk :(
Because `NULL` is not equal to anything, even `NULL != NULL`, we only can check
with `IS NULL` or `IS NOT NULL`.

## `VARCHAR` or `TEXT`

Expand Down Expand Up @@ -192,4 +193,6 @@ FROM information_schema.statistics;
- [Difference between text and varchar (character varying)](https://stackoverflow.com/a/4849030)
- [How to get the number of total results when there is LIMIT in query?](https://stackoverflow.com/q/33889922)
- [Run a query with a LIMIT/OFFSET and also get the total number of rows](https://stackoverflow.com/q/28888375)
- [SQL best practices – don’t compare count(*) with 0](https://www.depesz.com/2024/12/01/sql-best-practices-dont-compare-count-with-0/)
- [SQL best practices – don’t compare count with 0](https://www.depesz.com/2024/12/01/sql-best-practices-dont-compare-count-with-0/)
- [SQL NULLs are Weird!](https://jirevwe.github.io/sql-nulls-are-weird.html)
- [NULL Handling in SQLite Versus Other Database Engines](https://www.sqlite.org/nulls.html)

0 comments on commit 0c7cefa

Please sign in to comment.