Repository: tobymao/sqlglot

Issue:
Tilde operator fails to parse with the duckdb dialect
Fails for duckdb, but works for postgres:

```
In [1]: import sqlglot as sg

In [2]: sg.__version__
Out[2]: '11.4.1'

In [3]: sg.parse_one("select x ~ y", read="postgres")
Out[3]:
(SELECT expressions:
  (REGEXPLIKE this:
    (COLUMN this:
      (IDENTIFIER this: x, quoted: False)), expression:
    (COLUMN this:
      (IDENTIFIER this: y, quoted: False))))

In [4]: sg.parse_one("select x ~ y", read="duckdb")
...
ParseError: Invalid expression / Unexpected token. Line 1, Col: 10.
  select x ~ y
```

`~` is a valid duckdb operator:

```
❯ duckdb
v0.7.1
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D select 'x' ~ 'y' as m;
┌─────────┐
│    m    │
│ boolean │
├─────────┤
│ false   │
└─────────┘
```

Discussion:

Patch:
diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py
index e773dff5..c0342080 100644
--- a/sqlglot/dialects/duckdb.py
+++ b/sqlglot/dialects/duckdb.py
@@ -80,6 +80,7 @@ class DuckDB(Dialect):
     class Tokenizer(tokens.Tokenizer):
         KEYWORDS = {
             **tokens.Tokenizer.KEYWORDS,
+            "~": TokenType.RLIKE,
             ":=": TokenType.EQ,
             "ATTACH": TokenType.COMMAND,
             "BINARY": TokenType.VARBINARY,


Test patch:
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py
index 1cabade9..a15e6b45 100644
--- a/tests/dialects/test_duckdb.py
+++ b/tests/dialects/test_duckdb.py
@@ -125,6 +125,7 @@ class TestDuckDB(Validator):
             "SELECT a['x space'] FROM (SELECT {'x space': 1, 'y': 2, 'z': 3} AS a)"
         )
 
+        self.validate_all("x ~ y", write={"duckdb": "REGEXP_MATCHES(x, y)"})
         self.validate_all("SELECT * FROM 'x.y'", write={"duckdb": 'SELECT * FROM "x.y"'})
         self.validate_all(
             "WITH 'x' AS (SELECT 1) SELECT * FROM x",