PostgreSQL ROUND 함수 데이터형

PostgreSQL

ROUND function 시 데이터형을 명시해야 정확한 값이 나온다.

(예시)

SELECT ROUND((1412/231),2)
FROM 스키마.테이블;

--결과 : 6.00
SELECT ROUND((1412/231::numeric),2)
FROM 스키마.테이블;

--결과 : 6.12
SELECT round((1412::numeric/231),2)
FROM 스키마.테이블;

--결과 : 6.12
SELECT round((1412::numeric/231::numeric),2)
FROM 스키마.테이블;

--결과 : 6.12

PostgreSQL Data type

  1. Boolean
    1. True
    2. False
    3. NULL
  2. Character
    1. Char(n)
    2. Varchar(n)
    3. Text : 문자길이 제한이 없음
  3. Number
    1. Integers
      1. Small integer (smallint)
      2. Integer (int)
      3. Serial
    2. Floating-point number
      1. Float(n)
      2. Real or Float8
      3. Numeric or Numeric(p,s)
  4. Temporal Data Type
    1. Date : date value only
    2. Time : day value
    3. Timestamp : date + time
    4. Interval : periods of time
    5. Timestamptz : timestamp + time zone data
  5. Special Data Type
    1. Box : a rectangular box
    2. Line : a set of points
    3. Point :  a geometric pair of numbers
    4. Lseg : a line segment
    5. Polygon : a closed geometric
    6. Inet : an IP4 address
    7. Macaddr :a  MAC address
  6. Arrays Data Type

 

출처 : https://www.youtube.com/watch?v=aUfPf-clLLs