Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add support for BETWEEN
  • Loading branch information
dbrattli committed Aug 5, 2021
commit 151371e883a20373197d4a3307e19dc7ba89b41d
12 changes: 12 additions & 0 deletions src/NpgsqlFSharpParser/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ let stringLiteral : Parser<Expr, unit> =
spacesOrComment >>. quotedString .>> spacesOrComment
|>> Expr.StringLiteral

let between' : Parser<Expr, unit> =
attempt (
spaces >>.
identifier >>= (fun value ->
text "BETWEEN" >>.
(integer <|> number <|> date) >>= (fun left ->
text "AND" >>.
expr >>= (fun right ->
preturn (Expr.Between (value, left, right)))))
)

/// Parses 2 or more comma separated values. I.e (1, 2), but not (3) which will become an integer.
let numericList =
let numeric = integer <|> number
Expand Down Expand Up @@ -506,6 +517,7 @@ opp.TermParser <- choice [
(attempt declareQuery)
(attempt fetchQuery)
(attempt functionExpr)
between'
numericList
stringList
(text "(") >>. expr .>> (text ")")
Expand Down
18 changes: 18 additions & 0 deletions tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -687,5 +687,23 @@ let selectQueryTests = testList "Parse SELECT tests" [
)
)
}

testSelect """
SELECT *
FROM employees
WHERE employee_id BETWEEN 200 AND 300;
""" {
SelectExpr.Default with
Columns = [ Expr.Star ]
From = Some (Expr.Ident "employees")
Where =
Some(
Expr.Between(
Expr.Ident "employee_id",
Expr.Integer(200L),
Expr.Integer(300L)
)
)
}
]