Re: named generic constraints [feature request]

Поиск
Список
Период
Сортировка
Искать
От
Caleb Cushing
Тема
Re: named generic constraints [feature request]
Дата
Msg-id
81bfc67a0912062026u41624a38jbb04cdc4758c7960@mail.gmail.com
Ответ на
Список
Дерево обсуждения
named generic constraints [feature request] Caleb Cushing <xenoterracide@gmail.com>
Re: named generic constraints [feature request] Pavel Stehule <pavel.stehule@gmail.com>
Re: named generic constraints [feature request] Caleb Cushing <xenoterracide@gmail.com>
Re: named generic constraints [feature request] Peter Eisentraut <peter_e@gmx.net>
Re: named generic constraints [feature request] Pavel Stehule <pavel.stehule@gmail.com>
Re: named generic constraints [feature request] Caleb Cushing <xenoterracide@gmail.com>
Re: named generic constraints [feature request] Pavel Stehule <pavel.stehule@gmail.com>
Re: named generic constraints [feature request] Caleb Cushing <xenoterracide@gmail.com>
Re: named generic constraints [feature request] Pavel Stehule <pavel.stehule@gmail.com>
Re: named generic constraints [feature request] Josh Berkus <josh@agliodbs.com>
> no -
>
> "--" is line comment in SQL - it same like "//" in C++

sorry didn't see this was updated. I know -- is a comment

I mean in sql <> means NOT your function name is emptystr which
implies it looks for an emptystr and returns true if the string is
found to be empty (at least in my mind). so if you want to create a
contrstraint of not empty you'd write NOT emptystr(col) however the
way you wrote it would only return true if the string was NOT <> empty
which is a double negative meaning that it is empty thereby rejecting
all but empty strings.

my final function that I wrote ended up looking like this (note: I
didn't specify to include whitespace in my original explanation.




CREATE OR REPLACE FUNCTION empty(TEXT)
RETURNS bool AS $$SELECT $1 ~ '^[[:space:]]*$';    $$ LANGUAGE sql       IMMUTABLE;
COMMENT ON FUNCTION empty(TEXT)       IS 'Find empty strings or strings containing only whitespace';

which I'm using like this (note: this is not the full table)
CREATE TABLE users (       user_name       TEXT    NOT NULL                               UNIQUE                               CHECK ( NOT empty( user_name ))
);

I still wish I could write,something like

CREATE CONSTRAINT empty CHECK ( VALUE NOT ~ '^[[:space:]]*$';)

CREATE TABLE users (       user_name       TEXT    NOT NULL                               UNIQUE                               CHECK ( NOT empty )
);CREATE TABLE roles (   role_name       TEXT    NOT NULL                               UNIQUE                               CHECK ( NOT empty)
);
-- 
Caleb Cushing

http://xenoterracide.blogspot.com

В списке pgsql-hackers по дате отправления
От: Greg Smith
Дата:
От: Greg Smith
Дата:
FAQ