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

From Adrian Klaver
Subject Re: [GENERAL] How to define the limit length for numeric type?
Date
Msg-id ab0855fa-538c-bf07-f2c2-3c1a8c7955dd@aklaver.com
Whole thread Raw
In response to Re: [GENERAL] How to define the limit length for numeric type?  (vod vos <vodvos@zoho.com>)
List pgsql-general
On 03/12/2017 12:33 AM, vod vos wrote:
> So there is  no other simpler method for checking that? like varchar(4), only 4 char can be input?

That is not how that works:

test=# create table  varchar_test(fld_1 varchar(4));
CREATE TABLE

test=# \d varchar_test
         Table "public.varchar_test"
  Column |         Type         | Modifiers
--------+----------------------+-----------
  fld_1  | character varying(4) |

INSERT INTO varchar_test VALUES ('test'), ('tes'), ('te'), ('t');
INSERT 0 4

test=# select * from varchar_test ;
  fld_1
-------
  test
  tes
  te
  t
(4 rows)

test=# INSERT INTO varchar_test VALUES ('tests');
ERROR:  value too long for type character varying(4)

It just sets the upper limit of what can be entered.

>
> would using regexp cost more CPU or memory resources?
>
>



--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: [GENERAL] Index using in jsonb query
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] How to define the limit length for numeric type?