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
{{ message }}
This repository was archived by the owner on Mar 16, 2026. It is now read-only.
OS type and version: Windows 10 Pro, macOS Ventura 13.4
Python version: 3.8.10
pip version: 23.1.2
sqlalchemy-bigquery version: 1.6.1
Steps to reproduce
Compose an SQL statement using SQLAlchemy Core or ORM which includes a GROUP BY clause with an expression timestamp_trunc(`some_column`, hour)
Render it (or execute it and confirm how it was rendered by examining SQLAlchemy's log)
Code example
Below is an example script to reproduce the symptom. Please refer to the first comment block in the file for detail.
"""An example script to reproduce the bug.Executing this script outputs (partially folded for ease of reading): sqlalchemy: 1.4.49 sqlalchemy-bigquery: 1.6.1 SQLite---------------------------------------- SELECT timestamp_trunc(sensor.time, hour) AS time, max(sensor.value) AS max_1 FROM sensor GROUP BY timestamp_trunc(sensor.time, hour) BigQuery---------------------------------------- SELECT timestamp_trunc(`sensor`.`time`, hour) AS `time`, max(`sensor`.`value`) AS `max_1` FROM `sensor` GROUP BY `timestamp_trunc_1`In the final line, there is a reference to a non-existing colunnof which name is `timestamp_trunc_1`. The line should be rendered as: GROUP BY timestamp_trunc(`sensor`.`time`, hour)...like the rendering result for SQLite, written above."""importsqlalchemyassaimportsqlalchemy.dialects.sqliteassqliteimportsqlalchemy_bigqueryasbigqueryprint("sqlalchemy: ", sa.__version__)
print("sqlalchemy-bigquery:", bigquery.__version__)
engine=sa.create_engine("sqlite://")
metadata=sa.MetaData()
sensor_table=sa.Table(
"sensor",
metadata,
sa.Column("time", sa.TIMESTAMP),
sa.Column("value", sa.String),
)
stmt=sa.select(
sa.func.timestamp_trunc(sensor_table.c.time, sa.text("hour")).label("time"),
sa.func.max(sensor_table.c.value),
).group_by(
sa.func.timestamp_trunc(sensor_table.c.time, sa.text("hour")),
)
print("SQLite"+"-"*40)
print(
stmt.compile(
dialect=sqlite.dialect(),
compile_kwargs={"literal_binds": True},
),
)
print("BigQuery"+"-"*40)
print(
stmt.compile(
dialect=bigquery.dialect(),
compile_kwargs={"literal_binds": True},
),
)
Stack trace
N/A (no exception will be raised unless you send it to BigQuery)
Environment details
sqlalchemy-bigqueryversion: 1.6.1Steps to reproduce
timestamp_trunc(`some_column`, hour)Code example
Below is an example script to reproduce the symptom. Please refer to the first comment block in the file for detail.
Stack trace
N/A (no exception will be raised unless you send it to BigQuery)