You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, we ran into the following change of behaviour in 25.1.0.
>>> from sqlglot import parse_one
>>> parse_one("SELECT unnest(ARRAY[1, 2, 3])").sql()
'SELECT UNNEST(1, 2, 3)'
>>> parse_one("SELECT unnest(ARRAY[1, 2, 3])").sql(dialect="postgres")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/expressions.py", line 597, in sql
return Dialect.get_or_raise(dialect).generate(self, **opts)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/dialects/dialect.py", line 538, in generate
return self.generator(**opts).generate(expression, copy=copy)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/generator.py", line 623, in generate
sql = self.sql(expression).strip()
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/generator.py", line 777, in sql
sql = transform(self, expression)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/transforms.py", line 650, in _to_sql
return _sql_handler(expression)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/generator.py", line 2302, in select_sql
expressions = self.expressions(expression)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/generator.py", line 3371, in expressions
sql = self.sql(e, comment=False)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/generator.py", line 782, in sql
sql = getattr(self, exp_handler_name)(expression)
File "/home/ronan/.virtualenvs/insitu/lib/python3.9/site-packages/sqlglot/dialects/postgres.py", line 584, in unnest_sql
if len(expression.expressions) == 1:
TypeError: object of type 'Array' has no len()
>>> parse_one("SELECT unnest(ARRAY[1, 2, 3])", dialect="postgres").sql(dialect="postgres")
'SELECT UNNEST(ARRAY[1, 2, 3])'
I realized that this only occurs when the read dialect is not specified, so the workaround for us was to make sure that we added the dialect parameter to parse_one(), but I thought I would file the issue in case it would be useful.
The text was updated successfully, but these errors were encountered:
so the workaround for us was to make sure that we added the dialect parameter to parse_one()
I'd suggest this anyway because it's more stable vs using the base dialect.
@tobymao it's because Unnest now inherits from Func, so when it's used in places other than FROM, JOIN etc we now parse it in _parse_function_call as exp.Unnest, vs exp.Anonymous which was the behavior before 6a607d3.
Hi, we ran into the following change of behaviour in 25.1.0.
I realized that this only occurs when the read dialect is not specified, so the workaround for us was to make sure that we added the dialect parameter to
parse_one()
, but I thought I would file the issue in case it would be useful.The text was updated successfully, but these errors were encountered: