Hello

> -----Original Message-----
> From: pgsql-general-ow...@postgresql.org 
> [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of vod vos
> Sent: Sonntag, 12. März 2017 07:15
> To: pgsql-general <pgsql-general@postgresql.org>
> Subject: [GENERAL] How to define the limit length for numeric type?
> 
> 
> Hi everyone,
> 
> 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?

Maybe with a CHECK constraint?

CREATE TABLE test
(
  id serial,
  goose numeric(4,1),
  CHECK (goose > 30.2)
);

INSERT INTO test (goose) VALUES (300.2);
INSERT 0 1

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).

Of course you should set the correct value that you want to use in the 
contraint definition.

Regards
Charles

> 
> Thank you.
> 
> 
> 
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make 
> changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to