Re: How to add month.year column validation

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Andrus" <kobruleht2(at)hot(dot)ee>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to add month.year column validation
Date: 2009-12-22 20:13:54
Message-ID: D425483C2C5C9F49B5B7A41F8944154702962688@postal.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Andrus
> Sent: Tuesday, December 22, 2009 12:03 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] How to add month.year column validation
>
> Database contains CHAR(7) type column which must be NOT NULL and must
> be in
> the format
>
> mm.yyyy
>
> where:
>
> mm - month number, always two digits in range 01 .. 12
>
> . - separator must be point always.
>
> yyyy - must be four digits in range approx. 1980 .. 2110 .
>
> How to add column validation to table column which forces this ?

If you use a date (IOW, just always use a day of 1) then error detection
is automatic. It also only consumes 4 bytes of storage.

You can also use a check constraint, or create a domain.
http://www.postgresql.org/docs/8.4/static/ddl-constraints.html
http://www.postgresql.org/docs/current/static/sql-createdomain.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2009-12-22 20:14:10 Re: How to add month.year column validation
Previous Message Francisco Reyes 2009-12-22 20:10:55 Re: Not finding RPMs for 8.4.2!