Created
October 15, 2020 15:10
-
-
Save mbj/1f34de553642c595917b52b5b92e5d2c to your computer and use it in GitHub Desktop.
Postgresql logical implication operator
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 | |
logical_implication(a boolean, b boolean) | |
RETURNS | |
boolean | |
LANGUAGE | |
sql | |
IMMUTABLE | |
PARALLEL SAFE | |
RETURNS NULL ON NULL INPUT | |
COST 1 | |
AS $$ | |
SELECT NOT a OR b | |
$$ | |
; | |
CREATE OPERATOR -> | |
( function = logical_implication | |
, leftarg = boolean | |
, rightarg = boolean | |
) | |
; |
Not checked the boolean table for that one yet, still I think that OR NOT
is "hard" on the human mind in regular SQL, especially as the human than had to triple check precedence rules. I'd still prefer the operator.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can simply 'OR NOT'