Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
<tomcaml@yahoo.com> wrote in message
news:1146665511.174660.45060@i40g2000cwc.googlegroups.com...
> hello!
>
> is it possible to wrap a function such as TRIM around a check
> constraint?
>
> my constraint says field <> ' '
>
> and if someone enters ' ' , i want to TRIM that to one blank
> space and then have the check constraint get applied to the field to
> reject this kind of entry
>
> Thanks in advance!
>
> Tom
It works on 9.4:
CREATE TABLE test (value CHAR(10) CHECK (TRIM(value) != ' '));
However, this is unnecessary, as trailing spaces are ignored, e.g.:
CREATE TABLE test (value CHAR(10) CHECK (value != ' ')); -- Statement executed.
INSERT INTO test VALUES (' '); -- SQL Error (-530): Check constraint (tlsadm.c3144_1930) failed.
The result is the same with CHAR or VARCHAR.
--
Regards,
Doug Lawry
www.douglawry.webhop.org
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.