Where can I find detail information about constraint ?

Started by 纪晓曦over 16 years ago3 messagesgeneral
Jump to latest
#1纪晓曦
sheepjxx@gmail.com

I want detail usage introduction about constraint,such as how to constrain a
string to be exactly 4 character and start with 'z'.Where can I find the
reference of CHECK? detail usage.

In reply to: 纪晓曦 (#1)
Re: Where can I find detail information about constraint ?

On 23/09/2009 11:23, 纪晓曦 wrote:

I want detail usage introduction about constraint,such as how to
constrain a string to be exactly 4 character and start with 'z'.
Where can I find the reference of CHECK? detail usage.

Try the documentation, presumably under CREATE TABLE:

http://www.postgresql.org/docs

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

#3Laurenz Albe
laurenz.albe@cybertec.at
In reply to: 纪晓曦 (#1)
Re: Where can I find detail information about constraint ?

??? wrote:

I want detail usage introduction about constraint,such as how
to constrain a string to be exactly 4 character and start with 'z'.
Where can I find the reference of CHECK? detail usage.

Documentation:
http://www.postgresql.org/docs/current/static/ddl-constraints.html#AEN2254

The check you want would look similar to this:
CHECK (length(val) = 4 AND substr(val, 1, 1) = 'z')

Yours,
Laurenz Albe