diff --git a/sqlglot/generator.py b/sqlglot/generator.py index e1983f2077..857eff1459 100644 --- a/sqlglot/generator.py +++ b/sqlglot/generator.py @@ -904,7 +904,8 @@ def index_sql(self, expression: exp.Index) -> str: unique = "UNIQUE " if expression.args.get("unique") else "" primary = "PRIMARY " if expression.args.get("primary") else "" amp = "AMP " if expression.args.get("amp") else "" - name = f"{expression.name} " if expression.name else "" + name = self.sql(expression, "this") + name = f"{name} " if name else "" table = self.sql(expression, "table") table = f"{self.INDEX_ON} {table} " if table else "" using = self.sql(expression, "using") diff --git a/tests/fixtures/identity.sql b/tests/fixtures/identity.sql index 9a25768e20..5b2c29c159 100644 --- a/tests/fixtures/identity.sql +++ b/tests/fixtures/identity.sql @@ -617,6 +617,7 @@ CREATE FUNCTION a() LANGUAGE sql RETURNS INT CREATE FUNCTION a.b(x INT) RETURNS INT AS RETURN x + 1 CREATE FUNCTION a.b.c() CREATE INDEX abc ON t (a) +CREATE INDEX "abc" ON t (a) CREATE INDEX abc ON t (a, b, b) CREATE INDEX abc ON t (a NULLS LAST) CREATE INDEX pointloc ON points USING GIST(BOX(location, location))