Last active
December 17, 2015 11:58
-
-
Save robertsosinski/5605881 to your computer and use it in GitHub Desktop.
Additional logic operators for PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION xor(bool, bool) RETURNS bool AS 'SELECT ($1 AND NOT $2) OR (NOT $1 AND $2);' LANGUAGE 'sql'; | |
CREATE OPERATOR ~| (PROCEDURE='xor', LEFTARG=bool, RIGHTARG=bool); | |
CREATE FUNCTION condition(bool, bool) RETURNS bool AS 'SELECT CASE WHEN $1 AND NOT $2 THEN false ELSE true END;' LANGUAGE 'sql'; | |
CREATE OPERATOR -> (PROCEDURE='condition', LEFTARG=bool, RIGHTARG=bool); | |
CREATE FUNCTION bicondition(bool, bool) RETURNS bool AS 'SELECT CASE WHEN ($1 AND $2) OR (NOT $1 and NOT $2) THEN true ELSE false END;' LANGUAGE 'sql'; | |
CREATE OPERATOR <-> (PROCEDURE='bicondition', LEFTARG=bool, RIGHTARG=bool); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment