Skip to content

Commit

Permalink
feat: add postfresql install post
Browse files Browse the repository at this point in the history
  • Loading branch information
owenlongbo committed Feb 4, 2024
1 parent cab6d04 commit ca86f6d
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 0 deletions.
94 changes: 94 additions & 0 deletions blog/postgresql-isnull/postgresql-isnull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
slug: postgresql-isnull
title: Best Practices for PostgreSQL ISNULL and ISNOTNULL
description: 'This article explains how to use the `IS NULL` operator in PostgreSQL to check if a value is `NULL`. PostgreSQL `IS NULL` is a boolean operator that checks if a value is `NULL`. A `NULL` value is a special value that indicates nothing, it is neither an empty string nor false.'
authors: [ owen ]
image: https://cdn.illacloud.com/illa-website/blog/postgresql-isnull/cover.webp
tags: [ postgresql, isnull, isnotnull ]
date: 2024-02-04T11:00
is_featured: true
---

This article explains how to use the `IS NULL` operator in PostgreSQL to check if a value is `NULL`.
PostgreSQL `IS NULL` is a boolean operator that checks if a value is `NULL`. A `NULL` value is a special value that
indicates nothing, it is neither an empty string nor false.

## PostgreSQL IS NULL Syntax

PostgreSQL `IS NULL` is a unary comparison operator that only requires one operand. The syntax for the `IS NULL`
operator is:

```shell
expr IS NULL
expr IS NOT NULL
```

**Breakdown:**

- `expr` can be a field name, a value, or an expression.
- `IS NOT NULL` is the negation of `IS NULL`.
- `IS NULL` and `IS NOT NULL` can be used in `SELECT` statements or `WHERE` clauses.

## PostgreSQL IS NULL Operator Rules

When the operand on the left side of the PostgreSQL `IS NULL` operator is `NULL`, the `IS NULL` operator returns `t`,
otherwise it returns `f`.

```shell
SELECT
NULL IS NULL "NULL IS NULL",
0 IS NULL "0 IS NULL",
1 IS NULL "1 IS NULL";
```

```shell
NULL IS NOT NULL | 0 IS NOT NULL | 1 IS NOT NULL
------------------+---------------+---------------
f | t | t
```

## PostgreSQL IS NULL Examples

We will use the tables in the `Sakila` sample database for demonstration. Please install the `Sakila` sample database in
PostgreSQL first.

The `Sakila` sample database is one of the most widely used and best sample databases. The `Sakila` sample database was
originally developed by Mike Hillyer, a former member of the MySQL AB documentation team. It is designed to provide a
standard schema that can be used for example demonstrations in books, tutorials, articles, etc.

The `Sakila` database models a DVD rental store business, including movies, actors, movie-actor relationships, and a
central inventory table that connects movies, stores, and rental transactions.

As one of the best sample databases, the `Sakila` database has been ported to platforms such as PostgreSQL, Oracle, DB2,
and SQLite.

In the `Sakila` sample database, the `staff` table stores employee information for the DVD rental store.

In the `staff` table, `picture` stores the employee's photo file. To query for employees who have not uploaded a photo
from the `staff` table, you need to check if `picture` is `NULL`. Use the following SQL statement with `IS NULL`:

```shell
SELECT
first_name, last_name, picture
FROM
staff
WHERE
picture IS NULL;
```

```shell
first_name | last_name | picture
------------+-----------+---------
Mike | Hillyer | <null>
Jon | Stephens | <null>
```

## Conclusion

In this article, we learned the syntax and usage of the `IS NULL` and `IS NOT NULL` comparison operators in PostgreSQL.
Here are the key takeaways from this article:

- `IS NULL` and `IS NOT NULL` are unary comparison operators.
- Use the `IS NULL` operator to check if a value is `NULL`.
- The `IS NOT NULL` operator is the negation of `IS NULL`.
- `NULL IS NULL` evaluates to true.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
slug: postgresql-isnull
title: Best Practices for PostgreSQL ISNULL and ISNOTNULL
description: 'Dieser Artikel erläutert die Verwendung des `IS NULL`-Operators in PostgreSQL, um zu überprüfen, ob ein Wert `NULL` ist. PostgreSQL `IS NULL` ist ein boolescher Operator, der prüft, ob ein Wert `NULL` ist. Ein `NULL`-Wert ist ein spezieller Wert, der nichts anzeigt. Es ist weder ein leerer String noch falsch.'
authors: [ owen ]
image: https://cdn.illacloud.com/illa-website/blog/postgresql-isnull/cover.webp
tags: [ postgresql, isnull, isnotnull ]
date: 2024-02-04T11:00
is_featured: true
---

Dieser Artikel erläutert die Verwendung des `IS NULL`-Operators in PostgreSQL, um zu überprüfen, ob ein Wert `NULL` ist.
PostgreSQL `IS NULL` ist ein boolescher Operator, der prüft, ob ein Wert `NULL` ist. Ein `NULL`-Wert ist ein spezieller Wert, der
nichts anzeigt. Es ist weder ein leerer String noch falsch.

## PostgreSQL IS NULL Syntax

PostgreSQL `IS NULL` ist ein unärer Vergleichsoperator, der nur einen Operanden erfordert. Die Syntax für den `IS NULL`
Operator lautet:

```shell
expr IS NULL
expr IS NOT NULL
```

**Aufschlüsselung:**

- `expr` kann ein Feldname, ein Wert oder ein Ausdruck sein.
- `IS NOT NULL` ist die Negation von `IS NULL`.
- `IS NULL` und `IS NOT NULL` können in `SELECT`-Anweisungen oder `WHERE`-Klauseln verwendet werden.

## PostgreSQL IS NULL Operator Regeln

Wenn der Operand auf der linken Seite des PostgreSQL `IS NULL`-Operators `NULL` ist, gibt der `IS NULL`-Operator `t` zurück,
sonst gibt er `f` zurück.

```shell
SELECT
NULL IS NULL "NULL IS NULL",
0 IS NULL "0 IS NULL",
1 IS NULL "1 IS NULL";
```

```shell
NULL IS NOT NULL | 0 IS NOT NULL | 1 IS NOT NULL
------------------+---------------+---------------
f | t | t
```

## PostgreSQL IS NULL Beispiele

Wir werden die Tabellen in der `Sakila`-Beispieldatenbank für die Demonstration verwenden. Installieren Sie zuerst die
`Sakila`-Beispieldatenbank in PostgreSQL.

Die `Sakila`-Beispieldatenbank ist eine der am weitesten verbreiteten und besten Beispieldatenbanken. Die `Sakila`-Beispieldatenbank
wurde ursprünglich von Mike Hillyer, einem ehemaligen Mitglied des MySQL AB-Dokumentationsteams, entwickelt. Sie ist darauf
ausgelegt, ein standardisiertes Schema bereitzustellen, das für Beispielvorführungen in Büchern, Tutorials, Artikeln usw.
verwendet werden kann.

Die `Sakila`-Datenbank modelliert ein DVD-Verleihgeschäft mit Filmen, Schauspielern, Film-Schauspieler-Beziehungen und einer
zentralen Inventartabelle, die Filme, Geschäfte und Verleihtransaktionen verbindet.

Als eine der besten Beispieldatenbanken wurde die `Sakila`-Datenbank auf Plattformen wie PostgreSQL, Oracle, DB2 und SQLite
portiert.

In der `Sakila`-Beispieldatenbank speichert die Tabelle `staff` Informationen zu Mitarbeitern des DVD-Verleihgeschäfts.

In der Tabelle `staff` speichert `picture` die Fotodatei des Mitarbeiters. Um nach Mitarbeitern zu suchen, die kein Foto
hochgeladen haben, müssen Sie überprüfen, ob `picture` `NULL` ist. Verwenden Sie die folgende SQL-Anweisung mit `IS NULL`:

```shell
SELECT
first_name, last_name, picture
FROM
staff
WHERE
picture IS NULL;
```

```shell
first_name | last_name | picture
------------+-----------+---------
Mike | Hillyer | <null>
Jon | Stephens | <null>
```

## Fazit

In diesem Artikel haben wir die Syntax und Verwendung der Vergleichsoperatoren `IS NULL` und `IS NOT NULL` in PostgreSQL
kennengelernt. Hier sind die wichtigsten Erkenntnisse aus diesem Artikel:

- `IS NULL` und `IS NOT NULL` sind unäre Vergleichsoperatoren.
- Verwenden Sie den `IS NULL`-Operator, um zu überprüfen, ob ein Wert `NULL` ist.
- Der `IS NOT NULL`-Operator ist die Negation von `IS NULL`.
- `NULL IS NULL` ergibt `true`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
slug: postgresql-isnull
title: PostgreSQLのISNULLおよびISNOTNULLのベストプラクティス
description: 'この記事では、PostgreSQLの `IS NULL` 演算子を使用して値が `NULL` かどうかを確認する方法について説明します。PostgreSQLの `IS NULL` は、値が `NULL` かどうかを確認するブール演算子です。`NULL` 値は何も示さない特殊な値であり、空の文字列でもなく、falseでもありません。'
authors: [ owen ]
image: https://cdn.illacloud.com/illa-website/blog/postgresql-isnull/cover.webp
tags: [ postgresql, isnull, isnotnull ]
date: 2024-02-04T11:00
is_featured: true
---

この記事では、PostgreSQLの `IS NULL` 演算子を使用して値が `NULL` かどうかを確認する方法について説明します。PostgreSQLの `IS NULL` は、値が `NULL` かどうかを確認するブール演算子です。`NULL` 値は何も示さない特殊な値であり、空の文字列でもなく、falseでもありません。

## PostgreSQLのIS NULL構文

PostgreSQLの `IS NULL` は、単項比較演算子で、1つのオペランドだけが必要です。 `IS NULL` 演算子の構文は次のとおりです。

```shell
expr IS NULL
expr IS NOT NULL
```

**分解:**

- `expr` はフィールド名、値、または式になります。
- `IS NOT NULL``IS NULL` の否定です。
- `IS NULL` および `IS NOT NULL``SELECT` ステートメントまたは `WHERE` 句で使用できます。

## PostgreSQLのIS NULL演算子の規則

PostgreSQLの `IS NULL` 演算子の左側のオペランドが `NULL` の場合、`IS NULL` 演算子は `t` を返し、それ以外の場合は `f` を返します。

```shell
SELECT
NULL IS NULL "NULL IS NULL",
0 IS NULL "0 IS NULL",
1 IS NULL "1 IS NULL";
```

```shell
NULL IS NOT NULL | 0 IS NOT NULL | 1 IS NOT NULL
------------------+---------------+---------------
f | t | t
```

## PostgreSQLのIS NULLの例

デモンストレーションには `Sakila` サンプルデータベースのテーブルを使用します。まず、PostgreSQLに `Sakila` サンプルデータベースをインストールしてください。

`Sakila` サンプルデータベースは最も広く使用されているサンプルデータベースの1つです。`Sakila` サンプルデータベースは元々MySQL ABドキュメンテーションチームの元メンバーであるMike Hillyerによって開発されました。これは、本、チュートリアル、記事などでの例示に使用できる標準のスキーマを提供するように設計されています。

`Sakila` データベースはDVDレンタル店のビジネスをモデル化しており、映画、俳優、映画俳優の関係、および映画、店舗、レンタルトランザクションを接続する中央の在庫テーブルを含んでいます。

最高のサンプルデータベースの1つとして、`Sakila` データベースはPostgreSQL、Oracle、DB2、およびSQLiteなどのプラットフォームに移植されています。

`Sakila` サンプルデータベースでは、`staff` テーブルがDVDレンタル店の従業員情報を保存しています。

`staff` テーブルでは、`picture` が従業員の写真ファイルを保存しています。`staff` テーブルから写真をアップロードしていない従業員をクエリするには、`picture``NULL` かどうかを確認する必要があります。次の `IS NULL` を使用したSQLステートメントを使用します。

```shell
SELECT
first_name, last_name, picture
FROM
staff
WHERE
picture IS NULL;
```

```shell
first_name | last_name | picture
------------+-----------+---------
Mike | Hillyer | <null>
Jon | Stephens | <null>
```

## 結論

この記事では、PostgreSQLの `IS NULL` および `IS NOT NULL` 比較演算子の構文と使用方法を学びました。以下はこの記事の要点です。

- `IS NULL` および `IS NOT NULL` は単項比較演算子です。
- `IS NULL` 演算子を使用して値が `NULL` かどうかを確認します。
- `IS NOT NULL` 演算子は `IS NULL` の否定形です。
- `NULL IS NULL` は true と評価されます。
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
slug: postgresql-isnull
title: PostgreSQL中ISNULL和ISNOTNULL的最佳实践
description: '本文介绍了在 PostgreSQL 中如何使用 `IS NULL` 运算符检查一个值是不是 `NULL`。PostgreSQL `IS NULL` 是一个布尔运算符,它检查一个值是不是`NULL`。 `NULL`值是一个特殊的值,它表示什么都没有,它即不是空字符串也不是false。'
authors: [ owen ]
image: https://cdn.illacloud.com/illa-website/blog/postgresql-isnull/cover.webp
tags: [ postgresql, isnull, isnotnull ]
date: 2024-02-04T11:00
is_featured: true
---

本文介绍了在 PostgreSQL 中如何使用 `IS NULL` 运算符检查一个值是不是 `NULL`。PostgreSQL `IS NULL` 是一个布尔运算符,它检查一个值是不是`NULL``NULL`值是一个特殊的值,它表示什么都没有,它即不是空字符串也不是false。

## PostgreSQL IS NULL 语法

PostgreSQL `IS NULL` 是一个单目比较运算符,只需要一个操作数。`IS NULL` 运算符的语法是:

```shell
expr IS NULL
expr IS NOT NULL
```

解析:
- `expr`可以是一个字段名、一个值或者一个表达式。
- `IS NOT NULL``IS NULL` 的否定运算。
- `IS NULL``IS NOT NULL` 可以用在 `SELECT` 语句或者 `WHERE` 子句中。

## PostgreSQL IS NULL 运算规则

当 PostgreSQL `IS NULL` 运算符左侧的操作数是 `NULL` 时,`IS NULL` 运算符返回 `t`,否则返回 `f`

```shell
SELECT
NULL IS NULL "NULL IS NULL",
0 IS NULL "0 IS NULL",
1 IS NULL "1 IS NULL";
```

```shell
NULL IS NOT NULL | 0 IS NOT NULL | 1 IS NOT NULL
------------------+---------------+---------------
f | t | t
```

## PostgreSQL IS NULL 实例

我们将使用`Sakila`示例数据库 中的表进行演示,请您先在 PostgreSQL 中安装 `Sakila` 示例数据库。

`Sakila` 示例数据库是使用最广泛的示例数据库之一,也是最好的示例数据库之一。`Sakila` 示例数据库最初由 MySQL AB 文档团队的前成员 Mike Hillyer 开发。它旨在提供一个标准模式,可用于书籍、教程、文章等中的示例演示。

`Sakila` 数据库为 DVD 租赁商店业务建模,其中包含影片、演员、影片与演员关系等内容,以及连接影片、商店和租赁业务的中央库存表。

作为最好的示例数据库之一,`Sakila` 数据库已经被移植 PostgreSQL, Oracle, DB2, SQLite 等平台。

`Sakila` 示例数据库中, staff 表存储了 DVD 租赁商店中的职员信息。

`staff` 表中, `picture` 中存储了职员的照片文件, 要从 `staff` 表中查询那些没有上传图片的职员, 需要检查 `picture` 是否为 `NULL`, 请使用以下带有 `IS NULL` 的 SQL 语句:

```shell
SELECT
first_name, last_name, picture
FROM
staff
WHERE
picture IS NULL;
```

```shell
first_name | last_name | picture
------------+-----------+---------
Mike | Hillyer | <null>
Jon | Stephens | <null>
```

## 结论

在本文中,我们学习了 PostgreSQL 中 `IS NULL``IS NOT NULL` 比较运算符的语法和用法。本文要点如下:

- `IS NULL``IS NOT NULL` 是单目比较运算符。
- 使用 `IS NULL` 运算符检查一个值是否是 `NULL`
- `IS NOT NULL` 运算符是 `IS NULL` 的否定操作。
- `NULL IS NULL` 的结果是真。

0 comments on commit ca86f6d

Please sign in to comment.