Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/syntax/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ export interface ExprSubstring extends PGNode {

// === https://www.postgresql.org/docs/12/functions.html
export type LogicOperator = 'OR' | 'AND';
export type EqualityOperator = 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE' | '=' | '!=';
export type EqualityOperator = 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE' | '=' | '!=' | 'IS DISTINCT FROM' | 'IS NOT DISTINCT FROM';
// see https://www.postgresql.org/docs/12/functions-math.html
export type MathOpsBinary = '|' | '&' | '>>' | '^' | '#' | '<<' | '>>';
export type ComparisonOperator = '>' | '>=' | '<' | '<=' | '@>' | '<@' | '?' | '?|' | '?&' | '#>>' | '~' | '~*' | '!~' | '!~*' | '@@';
Expand Down
14 changes: 11 additions & 3 deletions src/syntax/expr.ne
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ expr_is
expr_compare -> expr_binary[op_scopable[%op_compare], expr_compare, expr_range]
expr_range -> expr_ternary[ops_between, %kw_and, expr_range, expr_others]
expr_others -> expr_binary[op_scopable[%ops_others], expr_others, expr_like]
expr_like -> expr_binary[op_single[ops_like], expr_like, expr_in]
expr_like -> expr_binary[op_single[ops_like], expr_like, expr_is_distinct_from]
expr_is_distinct_from -> expr_binary[op_single[ops_is_distinct_from], expr_is_distinct_from, expr_in]
expr_in -> expr_binary[op_single[ops_in], expr_in, expr_add]
expr_add -> expr_binary[op_scopable[(%op_plus | %op_minus | %op_additive)], expr_add, expr_mult]
expr_mult -> expr_binary[op_scopable[(%star | %op_div | %op_mod)], expr_mult, expr_exp]
Expand Down Expand Up @@ -252,8 +253,8 @@ expr_primary


# LIKE-kind operators
ops_like -> ops_like_keywors | ops_like_operators
ops_like_keywors -> %kw_not:? (%kw_like | %kw_ilike)
ops_like -> ops_like_keywords | ops_like_operators
ops_like_keywords -> %kw_not:? (%kw_like | %kw_ilike)
ops_like_operators
-> (%op_like {% () => 'LIKE' %})
| (%op_ilike {% () => 'ILIKE' %})
Expand Down Expand Up @@ -348,3 +349,10 @@ spe_substring -> (word {% kw('substring') %})

various_binaries
-> kw_at kw_time kw_zone {% () => 'AT TIME ZONE' %}


ops_is_distinct_from -> ops_is_distinct_from_keywords | ops_is_distinct_from_operators
ops_is_distinct_from_keywords -> %kw_is %kw_not:? %kw_distinct %kw_from
ops_is_distinct_from_operators
-> (%op_is_distinct_from {% () => 'IS DISTINCT FROM' %})
| (%op_is_not_distinct_from {% () => 'IS NOT DISTINCT FROM' %})
16 changes: 15 additions & 1 deletion src/syntax/expr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,20 @@ line`,
left: { type: 'ref', name: 'a' },
right: { type: 'ref', name: 'b' },
})

checkTreeExpr(['a is distinct from b', '"a" is distinct from "b"'], {
type: 'binary',
op: 'IS DISTINCT FROM',
left: { type: 'ref', name: 'a' },
right: { type: 'ref', name: 'b' },
});

checkTreeExpr(['a is not distinct from b', '"a" is not distinct from "b"'], {
type: 'binary',
op: 'IS NOT DISTINCT FROM',
left: { type: 'ref', name: 'a' },
right: { type: 'ref', name: 'b' },
});
});


Expand Down Expand Up @@ -1635,4 +1649,4 @@ line`,
args: [],
});
})
});
});