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

From Charles Clavadetscher
Subject Re: [GENERAL] How to define the limit length for numeric type?
Date
Msg-id 03ca01d29af9$3d568420$b8038c60$@swisspug.org
Whole thread Raw
In response to [GENERAL] How to define the limit length for numeric type?  (vod vos <vodvos@zoho.com>)
List pgsql-general
Hello

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@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



pgsql-general by date:

Previous
From: vod vos
Date:
Subject: [GENERAL] How to define the limit length for numeric type?
Next
From: Christoph Moench-Tegeder
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?