On 10/3/07, Filip Rembiałkowski <plk.zuber@gmail.com> wrote:
> 2007/10/3, Dawid Kuroczko <qnex42@gmail.com>:
>
> > CREATE TABLE rx_check (
> > rx text CHECK ('' ~ rx IN ('t','f'))
> > );
>
> wow. This is beautiful :)
Personally I would wrap it around DOMAIN, i.e.:
CREATE DOMAIN regex AS text CHECK ('' ~ VALUE IN (TRUE,FALSE));
And then use 'regex' type instead of 'text'. For a nice look&feel:
CREATE TABLE rx_test ( rx regex
);
qnex=>insert into rx_test values ('.*');
INSERT 0 1
qnex=>insert into rx_test values ('qwe');
INSERT 0 1
qnex=>insert into rx_test values ('aaa(aaa');
ERROR: invalid regular expression: parentheses () not balanced