Re: [GENERAL] How to define the limit length for numeric type? - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: [GENERAL] How to define the limit length for numeric type?
Date
Msg-id 20170312062417.GA1561@elch.exwg.net
Whole thread Raw
In response to [GENERAL] How to define the limit length for numeric type?  (vod vos <vodvos@zoho.com>)
List 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 by date:

Previous
From: "Charles Clavadetscher"
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?
Next
From: Pavel Stehule
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?