On Fri, Jul 07, 2006 at 11:34:57PM -0700, Richard Broersma Jr wrote: > "How do you ensure that a column will have a single alphabetic > character string in it? (That means no spaces, no numbers, and > no special characters.)"
You can check patterns with regular expressions. PostgreSQL supports SIMILAR TO, which is standard SQL since SQL:1999, and POSIX regular expressions; see "Pattern Matching" in the "Functions and Operators" chapter of the documentation: http://www.postgresql.org/docs/8.1/interactive/functions-matching.html Any of these CHECK expressions should work: CHECK (alpha_only SIMILAR TO '[A-Za-z]+') CHECK (alpha_only ~ '^[A-Za-z]+$') CHECK (alpha_only ~* '^[a-z]+$') Unfortunately, even though SIMILAR TO has been standard SQL for several years, not all databases implement it. Many databases do support regular expressions but generally via a non-standard syntax (as PostgreSQL does with its ~, ~*, !*, and !~* operators). -- Michael Fuhr ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match