Repository: tobymao/sqlglot

Issue:
Athena: escaped quotes in table/column comments not parsed correctly
On AWS Athena, table/column comments use backslash-escaped single quotes `\'`:

```sql
CREATE EXTERNAL TABLE my_table (
  id bigint COMMENT 'this is the row\'s id',
) LOCATION  's3://my-s3-bucket';
```

instead of the normal doubled-up quotes which it uses in normal strings:

```sql
select 'this is the row''s id';
```

This is required both when issuing `CREATE TABLE` statements as well as the output from `SHOW CREATE TABLE`. These, unfortunately, are not parsed by sqlglot and cause tokenization errors.

(Trino does not seem to have this behavior and uses normal double-up quotes everywhere.)

Discussion:

Fix (patch):
diff --git a/sqlglot/dialects/athena.py b/sqlglot/dialects/athena.py
index e2aaa967c4..df600eac7a 100644
--- a/sqlglot/dialects/athena.py
+++ b/sqlglot/dialects/athena.py
@@ -108,6 +108,7 @@ class Tokenizer(Trino.Tokenizer):
         """
 
         IDENTIFIERS = ['"', "`"]
+        STRING_ESCAPES = ["'", "\\"]
         KEYWORDS = {
             **Hive.Tokenizer.KEYWORDS,
             **Trino.Tokenizer.KEYWORDS,


Test changes:
diff --git a/tests/dialects/test_athena.py b/tests/dialects/test_athena.py
index dacaa4cae9..4f8a574305 100644
--- a/tests/dialects/test_athena.py
+++ b/tests/dialects/test_athena.py
@@ -7,6 +7,7 @@ class TestAthena(Validator):
     maxDiff = None
 
     def test_athena(self):
+        self.validate_identity("SELECT 'foo''bar'")
         self.validate_identity(
             "CREATE TABLE IF NOT EXISTS t (name STRING) LOCATION 's3://bucket/tmp/mytable/' TBLPROPERTIES ('table_type'='iceberg', 'FORMAT'='parquet')"
         )
@@ -39,6 +40,9 @@ def test_athena(self):
     def test_ddl(self):
         # Hive-like, https://docs.aws.amazon.com/athena/latest/ug/create-table.html
         self.validate_identity("CREATE EXTERNAL TABLE foo (id INT) COMMENT 'test comment'")
+        self.validate_identity(
+            "CREATE EXTERNAL TABLE my_table (id BIGINT COMMENT 'this is the row\\'s id') LOCATION 's3://my-s3-bucket'"
+        )
         self.validate_identity(
             "CREATE EXTERNAL TABLE foo (id INT, val STRING) CLUSTERED BY (id, val) INTO 10 BUCKETS"
         )