diff --git a/src/NpgsqlFSharpParser/Parser.fs b/src/NpgsqlFSharpParser/Parser.fs index c28a12c..ba2846c 100644 --- a/src/NpgsqlFSharpParser/Parser.fs +++ b/src/NpgsqlFSharpParser/Parser.fs @@ -245,7 +245,7 @@ let optionalFrom = optionalExpr ( attempt ( text "FROM " >>. simpleIdentifier >>= fun table -> - text "AS" >>= fun _ -> + optional (text "AS") >>= fun _ -> simpleIdentifier >>= fun alias -> preturn (Expr.As(Expr.Ident table, Expr.Ident alias)) ) diff --git a/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs b/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs index 12582ad..364b35b 100644 --- a/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs +++ b/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs @@ -124,6 +124,12 @@ let selectQueryTests = testList "Parse SELECT tests" [ From = Some (Expr.As(Expr.Ident "users", Expr.Ident "u")) } + testSelect "SELECT COUNT(*) AS user_count FROM users u" { + SelectExpr.Default with + Columns = [Expr.As(Expr.Function("COUNT", [Expr.Star]), Expr.Ident("user_count")) ] + From = Some (Expr.As(Expr.Ident "users", Expr.Ident "u")) + } + testSelect "SELECT COUNT(*) FROM users LIMIT 10" { SelectExpr.Default with Columns = [Expr.Function("COUNT", [Expr.Star]) ]