Re: [GENERAL] How to define the limit length for numeric type?

Поиск
Список
Период
Сортировка
От Christoph Moench-Tegeder
Тема Re: [GENERAL] How to define the limit length for numeric type?
Дата
Msg-id 20170312062417.GA1561@elch.exwg.net
обсуждение исходный текст
Ответ на [GENERAL] How to define the limit length for numeric type?  (vod vos <vodvos@zoho.com>)
Список pgsql-general
## vod vos (vodvos@zoho.com):

> How to define the exact limit length of numeric type? For example,
>
> CREATE TABLE test  (id serial, goose numeric(4,1));
>
> 300.2 and 30.2 can be inserted into COLUMN goose, but I want 30.2
> or 3.2 can not be inserted, how to do this?

testing=# CREATE TABLE test (
    id SERIAL,
    goose NUMERIC(4,1),
    CHECK (goose >= 100 OR goose <= -100)
    );
CREATE TABLE
testing=# INSERT INTO test (goose) VALUES (300.2);
INSERT 0 1
testing=# INSERT INTO test (goose) VALUES (30.2);
ERROR:  new row for relation "test" violates check constraint "test_goose_check"
DETAIL:  Failing row contains (2, 30.2).
testing=# INSERT INTO test (goose) VALUES (-300.2);
INSERT 0 1
testing=# INSERT INTO test (goose) VALUES (-30.2);
ERROR:  new row for relation "test" violates check constraint "test_goose_check"
DETAIL:  Failing row contains (4, -30.2).

Regards,
Christoph

--
Spare Space


В списке pgsql-general по дате отправления:

Предыдущее
От: "Charles Clavadetscher"
Дата:
Сообщение: Re: [GENERAL] How to define the limit length for numeric type?
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: [GENERAL] How to define the limit length for numeric type?