1
0

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 1 year has passed since last update.

PostgreSQLでNaNを扱う

Last updated at Posted at 2023-03-28

PostgreSQLでNaNを扱う

定数値としてのNaN

'NaN'::NUMERICという値が使えます。

postgres=# select 'NaN'::NUMERIC;
 numeric
---------
     NaN
(1 row)

postgres=#

NaNを判定する

'NaN'::NUMERICと比較すればよいですね。

postgres=# create table hoge (num1 numeric);
CREATE TABLE
postgres=# insert into hoge values('NaN'::NUMERIC);
INSERT 0 1
postgres=# select * from hoge;
 num1
------
  NaN
(1 row)

postgres=# select * from hoge where num1 = 'NaN'::NUMERIC;
 num1
------
  NaN
(1 row)

postgres=#

::NUMERICなくても

いけますね

postgres=# insert into hoge values('NaN');
INSERT 0 1
postgres=# select * from hoge;
 num1
------
  NaN
  NaN
(2 rows)

postgres=# select * from hoge where num1 = 'NaN';
 num1
------
  NaN
  NaN
(2 rows)

postgres=#

参考

マニュアルにも記載があった。
'Infinity'とか、'-Intinity'も使えますね。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?