2
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.

環境

CentOS7
PostgreSQL 11.18

算術関数とは?

数値に対して処理を行った結果を返す関数。

関数 説明
abs(int) 指定した数値の絶対値を返す
div(int1, int2) 指定したint1をint2で割った商を返す
mod(int1, int2) 指定したint1をint2で割った余りを返す
floor(int) 指定した数値より小さい最大の整数を返す
ceil(int) 指定した数値より大きい最小の整数を返す
round(int) 指定した数値の小数点部分を四捨五入した値を返す
trunc(int[, 小数点を切り捨てる位]) 指定した数値の小数点部分を、指定した位で切り捨てた値を返す
小数点を切り捨てる位を省略した場合は、小数点部分をすべて切り捨てる
random() 0以上1未満の範囲でランダムな値を返す

使ってみた

abs

postgres=# select abs(-5);
 abs 
-----
   5
(1 )

div

postgres=# select div(11, 2);
 div 
-----
   5
(1 )

mod

postgres=# select mod(11, 2);
 mod 
-----
   1
(1 )

floor

postgres=# select floor(2.12);
 floor 
-------
     2
(1 )

ceil

postgres=# select ceil(2.12);
 ceil 
------
    3
(1 )

round

postgres=# select round(2.65);
 round 
-------
     3
(1 )

trunc

postgres=# select trunc(2.12, 1);
 trunc 
-------
   2.1
(1 )

random

postgres=# select random();
      random       
-------------------
 0.562132634688169
(1 )

2
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
2
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?