programing

PSQL의 DECTION 및 NUMERICAL 데이터 유형 간의 차이

mailnote 2023. 5. 1. 21:40
반응형

PSQL의 DECTION 및 NUMERICAL 데이터 유형 간의 차이

무슨 소용이 있습니까?decimal그리고.numericpostgre의 데이터 유형SQL. 참고문헌에 따르면 이 자료형들에 대한 설명은 다음과 같습니다.

Decimal,numeric --> It is a user specified precision, exact and range up to 131072 digits before the decimal point and up to 16383 digits after the decimal point.

위의 문장은 다음의 설명을 보여줍니다.decimal그리고.numeric데이터 형식하지만 저는 여전히 이러한 데이터 유형의 정확한 용도와 다른 데이터 유형 대신 사용되는 위치를 이해하지 못했습니다.

예를 들어 답변해 주시면 대단히 감사하겠습니다...

설명서의 오른쪽:

종류decimal그리고.numeric동등합니다.두 유형 모두 SQL 표준의 일부입니다.

"사용해야 하는 이유"에 대해서도 설명서에 설명되어 있습니다.

숫자 유형은 숫자를 매우 많은 숫자로 저장하고 계산을 정확하게 수행할 수 있습니다.

(내 것 강조).

소수가 포함된 숫자가 필요한 경우decimal(또는)numeric만약 소수가 없는 숫자가 필요하다면,integer또는bigint의 일반적인 용도decimal열 유형은 "제품 가격" 열 또는 "이자율"이 될 수 있습니다.정수 유형의 일반적인 사용은 예를 들어 주문한 제품 를 저장하는 열입니다(제품을 "반" 주문할 수 없는 경우).

double그리고.real또한 십진수 값을 저장할 수 있는 유형이지만 대략적인 유형입니다.즉, 저장한 값을 반드시 검색할 필요는 없습니다.자세한 내용은 http://floating-point-gui.de/ 를 참조하십시오.

https://www.postgresql.org/message-id/20211.1325269672 @ss.pgh.pa.us 에서 직접 인용.

Postgres에서는 아무런 차이가 없습니다.SQL 표준에서는 두 가지 이름을 모두 사용해야 하므로 두 가지 유형의 이름이 있습니다.표준을 간단히 살펴보면 유일한 차이점은 다음과 같습니다.

     17)NUMERIC specifies the data type exact numeric, with the decimal
        precision and scale specified by the <precision> and <scale>.

     18)DECIMAL specifies the data type exact numeric, with the decimal
        scale specified by the <scale> and the implementation-defined
        decimal precision equal to or greater than the value of the
        specified <precision>.

즉, DECIMAL의 경우 소수점 왼쪽에 요청된 숫자보다 더 많은 숫자가 구현될 수 있습니다.포스트그레스는 그러한 자유를 행사하지 않기 때문에 우리에게 이 유형들 사이에는 차이가 없습니다.

      regards, tom lane

그들은 서로의 동의어이고 기능적으로 동일합니다.SQL:2003 표준은 다음과 같습니다.

21) NUMERIC specifies the data type
    exact numeric, with the decimal
    precision and scale specified by the
    <precision> and <scale>.

22) DECIMAL specifies the data type
    exact numeric, with the decimal scale
    specified by the <scale> and the
    implementation-defined decimal
    precision equal to or greater than the
    value of the specified <precision>.

언급URL : https://stackoverflow.com/questions/33730538/difference-between-decimal-and-numeric-datatype-in-psql

반응형