Re: Newbie question - Mailing list pgsql-admin

From Bruno Wolff III
Subject Re: Newbie question
Date
Msg-id 20030626203911.GA10461@wolff.to
Whole thread Raw
In response to Newbie question  ("Vinay" <vinay@mdp.net>)
Responses Re: Newbie question
List pgsql-admin
On Thu, Jun 26, 2003 at 15:59:55 -0400,
  Vinay <vinay@mdp.net> wrote:
> I have a very simple question regarding creating columns in a table
>
> Can we create a column in a table in such a way that it will allow only certain length, nothing less or nothing more
>
> here is an example
>
>
> create table test(column1 char(2));
>
> will create table with column1 which will accept characters upto length two.
> I want the column to accept the column value which is absolutely length of two.

A char(2) will always have two characters (unless it is NULL). If you want
to check for two nonblank characters or two letters or something like
that use a check constraint.

Some like:
create table test (
  col1 char(2) constraint bad_length check (col1 ~ '^[a-zA-Z][a-zA-Z]$'
);

pgsql-admin by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: Newbie question
Next
From: Michael Kovalcik
Date:
Subject: How do I select the last Id in a column???