Will return all rows where both posn_id and rid are not NULL and where they are different.
It's the ANSI SQL-Compliant not equals operator in a simple comparison predicate (WHERE statement). Colloquially, it's the "inequality operator". Though many databases accept an alternative !=, the spec itself does not mention != and it should not be used if <> is supported.
SQL uses three valued logic, with possible values being true, false or unknown. The WHERE clause filters out all rows except those where the predicate evaluates to true.
If either or both sides are null, the operator returns unknown.
On inequality, where both sides are not =, the operator returns true.
On equality, <> returns false.
On null treatment, a similar operator is IS DISTINCT FROM which treats nulls as ordinary values, from the PostgreSQL docs
For non-null inputs, IS DISTINCT FROM is the same as the <> operator. However, if both inputs are null it returns false, and if only one input is null it returns true.
For RDBMS specific documentation on comparison operators, see also
Theoretically, any user with the necessary privileges could create an operator with that operator name using CREATE OPERATOR - but not in the example you link to.
The lexer, encountering ! considers that the next character might be a continuation of the != operator, =, and if that happens, everything is fine. Otherwise, if the next character is of the same class (of characters which might be part of a logical operator, such as <) but doesn't match what's expected... then the next character just... disappears, apparently since ! is a complete logical operator by itself.
The result is that !! resolves to ! when not separated by whitespace...
Best Answer
Will return all rows where both
posn_id
andrid
are notNULL
and where they are different.It's the ANSI SQL-Compliant
not equals operator
in a simplecomparison predicate
(WHERE
statement). Colloquially, it's the "inequality operator". Though many databases accept an alternative!=
, the spec itself does not mention!=
and it should not be used if<>
is supported.SQL uses three valued logic, with possible values being
true
,false
orunknown
. TheWHERE
clause filters out all rows except those where the predicate evaluates totrue
.null
, the operator returnsunknown
.=
, the operator returns true.<>
returns false.On null treatment, a similar operator is
IS DISTINCT FROM
which treats nulls as ordinary values, from the PostgreSQL docsFor RDBMS specific documentation on comparison operators, see also
<>