18
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GREATEST(), LEAST()関数はPostgreSQLだけNULLの扱いが違う

Posted at

SQLには複数レコードから最大値/最小値を求める集約関数のMAX(), MIN()関数がありますが、そうでなく複数指定した引数のうちの最大値/最小値を求める関数を、SQL非標準ながら複数のRDBが持っています。
それがGREATEST(), LEAST()関数。

しかしこの両関数に渡した引数値にひとつでもNULLが含まれていた場合の振る舞いがPostgreSQLだけ違うので製品移行の際に注意が必要です。

RDB NULLが含まれた場合
Oracle NULLを返す
DB2
MySQL
SQLite
(多引数`MAX()`, `MIN()`)
BigQuery
**PostgreSQL** **NULLを無視し残りの値の最大または最小**
SQL Server (非搭載)
18
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?