「PostgreSQL」div関数で割り算の結果を取得する

環境
Windows 10 Home 64bit
PostgreSQL 13.2

関数
div(y numeric, x numeric)
戻り値型 numeric
y/xの整数商
div関数を使って、割り算の結果を取得します。

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# SELECT DIV(24,6) result;
result
--------
4
(1)
postgres=# SELECT DIV(24,6) result; result -------- 4 (1 行)
postgres=# SELECT DIV(24,6) result;
 result
--------
      4
(1 行)

使用例2
少数を割り算します
操作例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# SELECT DIV(24.5,6) result;
result
--------
4
(1)
postgres=# SELECT DIV(24.5,6) result; result -------- 4 (1 行)
postgres=# SELECT DIV(24.5,6) result;
 result
--------
      4
(1 行)

使用例3
マイナスを割り算します
操作例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# SELECT DIV(24.5,-6) resA,DIV(-24.5,-6) resB;
resa | resb
------+------
-4 | 4
(1)
postgres=# SELECT DIV(24.5,-6) resA,DIV(-24.5,-6) resB; resa | resb ------+------ -4 | 4 (1 行)
postgres=# SELECT DIV(24.5,-6) resA,DIV(-24.5,-6) resB;
 resa | resb
------+------
   -4 |    4
(1 行)

 

PostgreSQL

Posted by arkgame