Repository: sqlfluff/sqlfluff

Issue:
"space" not a reserved word in Postgres
The following SQL generates `L029 | Keywords should not be used as identifiers` due to the use of the alias `space`. 

```sql
SELECT 
    foo AS space
FROM 
    bar
;
```

`space` has no special status under Postgres: https://www.postgresql.org/docs/current/sql-keywords-appendix.html

I can submit a PR to silence L029 for `space` in the Postgres dialect, but first I wanted to make sure that doing so would be viewed as an enhancement. 🙂


Discussion:

Patch:
diff --git a/src/sqlfluff/dialects/dialect_postgres.py b/src/sqlfluff/dialects/dialect_postgres.py
index 3a8f83bc3..176f1f951 100644
--- a/src/sqlfluff/dialects/dialect_postgres.py
+++ b/src/sqlfluff/dialects/dialect_postgres.py
@@ -32,6 +32,9 @@ postgres_dialect.insert_lexer_struct(
 )
 
 
+# https://www.postgresql.org/docs/current/sql-keywords-appendix.html
+# SPACE has special status in some SQL dialects, but not Postgres.
+postgres_dialect.sets("unreserved_keywords").remove("SPACE")
 # Reserve WITHIN (required for the WithinGroupClauseSegment)
 postgres_dialect.sets("unreserved_keywords").remove("WITHIN")
 postgres_dialect.sets("reserved_keywords").add("WITHIN")


Test patch:
diff --git a/test/dialects/postgres_test.py b/test/dialects/postgres_test.py
index 4aca6c123..57a067194 100644
--- a/test/dialects/postgres_test.py
+++ b/test/dialects/postgres_test.py
@@ -21,3 +21,20 @@ def test_epoch_datetime_unit(raw):
     lnt = Linter(config=cfg)
     result = lnt.lint_string(raw)
     assert result.num_violations() == 0
+
+
+@pytest.mark.parametrize(
+    "raw",
+    [
+        "SELECT foo AS space FROM t1",
+        "SELECT space.something FROM t1 AS space",
+    ],
+)
+def test_space_is_not_reserved(raw):
+    """Ensure that SPACE is not treated as reserved."""
+    cfg = FluffConfig(
+        configs={"core": {"exclude_rules": "L009,L016,L031", "dialect": "postgres"}}
+    )
+    lnt = Linter(config=cfg)
+    result = lnt.lint_string(raw)
+    assert result.num_violations() == 0