Re: Celko's Puzzle Number 5

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Celko's Puzzle Number 5
Дата
Msg-id 20060708115403.GA13518@winnie.fuhr.org
обсуждение исходный текст
Ответ на Celko's Puzzle Number 5  (Richard Broersma Jr <rabroersma@yahoo.com>)
Ответы Re: Celko's Puzzle Number 5
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Patrice OLIVER
Дата:
Сообщение: unsubscribe
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: table joining duplicate records