원본출처 : http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=189
Submitted on: 04-24-2001
Description:
Uses the >>> operator as logical implication (called IMP in many systems, including Microsoft Access. The truth table for IMP is
1 T F
T t f
F t t
It can be used for things like 'if condition one is true, condition two must be true; otherwise, it doesn't really matter' I use it frequently as a quick shorthand in CHECK clauses.
Code:
-- author: joel burton (jburton@scw.org)
-- public domain
CREATE FUNCTION "imp" (boolean,boolean) RETURNS boolean AS '
begin
if ($2) or (not $1) then return ''t'';
end if;
return ''f'';
END;
' LANGUAGE 'plpgsql' WITH ( iscachable );
COMMENT ON FUNCTION "imp" ( boolean,boolean ) IS 'Logical implication';
CREATE OPERATOR >>> (PROCEDURE = imp ,
LEFTARG = boolean ,
RIGHTARG = boolean );
|