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>, "'rob stone'" <floriparob(at)gmail(dot)com>
Cc: "'pgsql-general'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to define the limit length for numeric type?
Date: 2017-03-13 15:06:31
Message-ID: 04e701d29c0b$6cf75ed0$46e61c70$@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: Montag, 13. März 2017 15:52
> To: rob stone <floriparob(at)gmail(dot)com>
> Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
> Subject: Re: [GENERAL] How to define the limit length for numeric type?
>
> Sorry for taking varchar(4) as an example, What I want urgently is how to make a constraint of fixed length of a
> numeric data, that you can only input data like 23.45, and if you input the data like 2.45, 23.4356, 233.45, you
> will get a warning message from postgresql.
>
> I think expr will do the job, but are there any simpler ways to do it in postgresql?

Well, I don't think that you will find anything simpler than using a regexp in a check constraint, as Tom and I did suggest.

https://www.postgresql.org/message-id/15358.1489336741%40sss.pgh.pa.us
https://www.postgresql.org/message-id/040301d29b01%2443d71f50%24cb855df0%24%40swisspug.org

I have some trouble understanding what you find so complicated in that solution?

Bye
Charles

>
>
> ---- On 星期日, 12 三月 2017 14:28:53 -0700 rob stone <floriparob(at)gmail(dot)com> wrote ---- > Hello, > > On Sat, 2017-
> 03-11 at 22:14 -0800, vod vos wrote:
> > > 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?
> > >
> > > Thank you.
> > >
> > >
> > >
> >
> >
> > Assuming that column goose may only contain values ranging from 100.0 > to 999.9, then a check constraint along
> the lines of:- > > goose > 99.9 and < 1000 > > should do the trick.
> >
> > HTH,
> > Rob
> >
> >
> > --
> > 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
> >
>
>
>
> --
> 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 David G. Johnston 2017-03-13 15:09:15 Re: How to define the limit length for numeric type?
Previous Message vod vos 2017-03-13 14:51:57 Re: How to define the limit length for numeric type?