check constraint on char field

From: Robert Fitzpatrick <robert(at)webtent(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: check constraint on char field
Date: 2004-06-09 16:42:52
Message-ID: 1086799372.3458.70.camel@columbus
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a field in my pgsql 7.4.2 table that is char(6) type. This holds
an ID that contains only numbers, but must be six characters in length.
First two chars are the year followed by a sequential number. For
instance, a number entered for the time this year would be '040001'. I
was trying to setup a check constraint to make sure only number were
used, this is what I have, but it is allowing alphanumerics:

projectno >= '000000' AND projectno <= '999999'

Or maybe just a trigger to create the number itself would be better?

--
Robert

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2004-06-09 16:54:50 Re: postgres on SuSE 9.1
Previous Message Martin Schäfer 2004-06-09 15:51:18 How to determine whether a view's column is indexed?