From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Vinay <vinay(at)mdp(dot)net> |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Newbie question |
Date: | 2003-06-26 20:39:11 |
Message-ID: | 20030626203911.GA10461@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Thu, Jun 26, 2003 at 15:59:55 -0400,
Vinay <vinay(at)mdp(dot)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]$'
);
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Goldberg | 2003-06-26 21:00:33 | Re: How do I select the last Id in a column??? |
Previous Message | scott.marlowe | 2003-06-26 20:29:08 | Re: Newbie question |