「PostgreSQL」小数部分の桁数を取得する

2022年3月17日

環境
Windows10 64bit
PostgreSQL 9.6.5

書式
scale(数値)
「scale」を使用して、小数部の桁数を取得します。

操作例
例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT scale(1.2) result;
SELECT scale(1.2) result;
SELECT scale(1.2) result;

結果 1

例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select scale(0.34) result;
select scale(0.34) result;
select scale(0.34) result;

結果 2

例3

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select scale(0.62345679) result;
select scale(0.62345679) result;
select scale(0.62345679) result;

結果 8

例4

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select scale(-5.67) result;
select scale(-5.67) result;
select scale(-5.67) result;

結果 2

PostgreSQL

Posted by arkgame