Repository: tobymao/sqlglot

Issue:
Bigquery parse unexpected token found (= ) in elseif clause
Code:

```python
import sqlglot

my_str = """BEGIN

DECLARE MY_VAR INT64 DEFAULT 1;

SET MY_VAR = (SELECT 0);

IF MY_VAR = 1 THEN
    SELECT 'TRUE';
ELSEIF MY_VAR = 0 THEN
    SELECT 'FALSE';
ELSE
    SELECT 'NULL';
END IF;
END
"""

parsed_objects = sqlglot.parse(my_str, dialect='bigquery')

print(parsed_objects)

```
error:
```
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 9, Col: 15.
  VAR INT64 DEFAULT 1;

SET MY_VAR = (SELECT 0);

IF MY_VAR = 1 THEN
    SELECT 'TRUE';
ELSEIF MY_VAR = 0 THEN
    SELECT 'FALSE';
ELSE
    SELECT 'NULL';
END IF;
END
```

`=` is underlined



Comments:

Patch:
diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py
index 3c8bb5f7..d4344f69 100644
--- a/sqlglot/dialects/bigquery.py
+++ b/sqlglot/dialects/bigquery.py
@@ -302,6 +302,7 @@ class BigQuery(Dialect):
             "BYTES": TokenType.BINARY,
             "CURRENT_DATETIME": TokenType.CURRENT_DATETIME,
             "DECLARE": TokenType.COMMAND,
+            "ELSEIF": TokenType.COMMAND,
             "EXCEPTION": TokenType.COMMAND,
             "FLOAT64": TokenType.DOUBLE,
             "FOR SYSTEM_TIME": TokenType.TIMESTAMP_SNAPSHOT,
@@ -410,6 +411,7 @@ class BigQuery(Dialect):
 
         STATEMENT_PARSERS = {
             **parser.Parser.STATEMENT_PARSERS,
+            TokenType.ELSE: lambda self: self._parse_as_command(self._prev),
             TokenType.END: lambda self: self._parse_as_command(self._prev),
             TokenType.FOR: lambda self: self._parse_for_in(),
         }


Test patch:
diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
index 37846da3..cf8cb3b6 100644
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -21,6 +21,7 @@ class TestBigQuery(Validator):
         self.validate_identity("SELECT * FROM x.*")
         self.validate_identity("SELECT * FROM x.y*")
 
+        self.validate_identity("CASE A WHEN 90 THEN 'red' WHEN 50 THEN 'blue' ELSE 'green' END")
         self.validate_identity("CREATE SCHEMA x DEFAULT COLLATE 'en'")
         self.validate_identity("CREATE TABLE x (y INT64) DEFAULT COLLATE 'en'")
         self.validate_identity("PARSE_JSON('{}', wide_number_mode => 'exact')")
@@ -1091,6 +1092,35 @@ WHERE
 
             self.assertIn("unsupported syntax", cm.output[0])
 
+        with self.assertLogs(helper_logger):
+            statements = parse(
+                """
+                BEGIN
+                    DECLARE MY_VAR INT64 DEFAULT 1;
+                    SET MY_VAR = (SELECT 0);
+
+                    IF MY_VAR = 1 THEN SELECT 'TRUE';
+                    ELSEIF MY_VAR = 0 THEN SELECT 'FALSE';
+                    ELSE SELECT 'NULL';
+                    END IF;
+                END
+                """,
+                read="bigquery",
+            )
+
+            expected_statements = (
+                "BEGIN DECLARE MY_VAR INT64 DEFAULT 1",
+                "SET MY_VAR = (SELECT 0)",
+                "IF MY_VAR = 1 THEN SELECT 'TRUE'",
+                "ELSEIF MY_VAR = 0 THEN SELECT 'FALSE'",
+                "ELSE SELECT 'NULL'",
+                "END IF",
+                "END",
+            )
+
+            for actual, expected in zip(statements, expected_statements):
+                self.assertEqual(actual.sql(dialect="bigquery"), expected)
+
         with self.assertLogs(helper_logger) as cm:
             self.validate_identity(
                 "SELECT * FROM t AS t(c1, c2)",