Обсуждение: Numeric Data Type

Поиск
Список
Период
Сортировка

Numeric Data Type

От
"Huy Do"
Дата:
Hi,

Can anyone give me an explanation of the numeric field.

for eg.

does numeric(2,1) mean a number with 2 digits before the decimal point
and 1 after (22.1),

or does it mean a number with a maximum of 2 digits and at least
1 of those digits have to be after the decimal point (2.1)

Thanks.

Huy

Re: Numeric Data Type

От
"Oliver Elphick"
Дата:
"Huy Do" wrote:
  >Hi,
  >
  >Can anyone give me an explanation of the numeric field.
  >
  >for eg.
  >
  >does numeric(2,1) mean a number with 2 digits before the decimal point
  >and 1 after (22.1),
  >
  >or does it mean a number with a maximum of 2 digits and at least
  >1 of those digits have to be after the decimal point (2.1)


junk=# create table xx (n numeric(2,1));
CREATE
junk=# insert into xx values (2.1);
INSERT 6705225 1
junk=# insert into xx values (22.1);
ERROR:  overflow on numeric ABS(value) >= 10^1 for field with precision 2 scale 1
junk=# insert into xx values (22);
ERROR:  overflow on numeric ABS(value) >= 10^1 for field with precision 2 scale 1
junk=# insert into xx values (.22);
INSERT 6705226 1
junk=# insert into xx values (.222);
INSERT 6705227 1
junk=# select * from xx;
  n
-----
 2.1
 0.2
 0.2
(3 rows)

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "And the angel said to her, " Do not be afraid, Mary;
      for you have found favor with God. And behold, you
      will conceive in your womb, and bear a son, and you
      shall name Him Jesus."       Luke 1:30,31