• 카테고리

    질문 & 답변
  • 세부 분야

    데이터베이스

  • 해결 여부

    미해결

round 에러

23.04.11 05:07 작성 조회수 299

1

select product_id, product_name , unit_price, round(sum(unit_price) over (order by unit_price),2) as unit_sum

from products ;

 

실행시 "SQL Error [42883]: 오류: round(real, integer) 이름의 함수가 없음"

sum(unit_price) over (order by unit_price)의 자료형이 real인 것은 확인이 되는데 왜 에러가 나는걸까요?

답변 1

답변을 작성해보세요.

1

안녕하십니까,

PostgreSQL이 묵시적인 형변환에 좀 엄격합니다. 아래와 같이 명시적으로 NUMERIC으로 변환하여 적용하시면 될 것 같습니다.

round((sum(unit_price) over (order by unit_price))::numeric, 2)

감사합니다.