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

From: "Charles Clavadetscher" <clavadetscher(at)swisspug(dot)org>
To: "'vod vos'" <vodvos(at)zoho(dot)com>, "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to define the limit length for numeric type?
Date: 2017-03-12 06:23:51
Message-ID: 03ca01d29af9$3d568420$b8038c60$@swisspug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of vod vos
> Sent: Sonntag, 12. März 2017 07:15
> To: pgsql-general <pgsql-general(at)postgresql(dot)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(at)postgresql(dot)org) To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Moench-Tegeder 2017-03-12 06:24:17 Re: How to define the limit length for numeric type?
Previous Message vod vos 2017-03-12 06:14:53 How to define the limit length for numeric type?