proposal: plpgsql - Assert statement
От | Pavel Stehule |
---|---|
Тема | proposal: plpgsql - Assert statement |
Дата | |
Msg-id | CAFj8pRDiWaACoHQwYbBn_YuW2UxpWFd1Y4o2XF5BO-zHNmfRaA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: proposal: plpgsql - Assert statement
Re: proposal: plpgsql - Assert statement |
Список | pgsql-hackers |
Hello
Assert is usually implemented as custom functions and used via PERFORM statement now-- usual current solution
PERFORM Assert(some expression) [ string expression or literal - explicit message ]
[ USING clause - same as RAISE stmt (possible in future ) ]
( ROW_COUNT ( = | <> ) ( 1 | 0 ) |ASSERT IS NOT NULL pk;
ASSERT QUERY SELECT id FROM tab WHERE x = 1;
ASSERT CHECK 2 = (SELECT count(*) FROM tab WHERE x = 1);
ASSERT WARNING "data are there" QUERY SELECT ...
Shorter variant should to work
CREATE OR REPLACE FUNCTION assert(boolean)
RETURNS void AS $$
BEGIN
ASSERT CHECK $1;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION assert(boolean, text)
RETURNS void AS $$
BEGIN
ASSERT $1 CHECK $2;
END;
$$ LANGUAGE plpgsql;
Usage:
PERFORM assert(a <> 10);
PERFORM assert(a <> 10, "a should be 10");
Comments, notices?
Regards
Pavel
Pavel
This design should not break any current solution, it allows a static analyses, and it doesn't close a door for future enhancing.
В списке pgsql-hackers по дате отправления: