From: | Christoph Moench-Tegeder <cmt(at)burggraben(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: How to define the limit length for numeric type? |
Date: | 2017-03-12 06:24:17 |
Message-ID: | 20170312062417.GA1561@elch.exwg.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
## vod vos (vodvos(at)zoho(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2017-03-12 06:25:19 | Re: How to define the limit length for numeric type? |
Previous Message | Charles Clavadetscher | 2017-03-12 06:23:51 | Re: How to define the limit length for numeric type? |