Skip to content

Commit

Permalink
fix: compile column before using as text
Browse files Browse the repository at this point in the history
without compiling the column is resolved as "table".column while it should be `table`.column
  • Loading branch information
nextchamp-saqib committed Jan 11, 2024
1 parent 50ea5ee commit f744ee1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion insights/insights/query_builders/sql_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sqlalchemy import Column, TextClause
from sqlalchemy import column as sa_column
from sqlalchemy import select, table
from sqlalchemy.dialects import mysql
from sqlalchemy.engine import Dialect
from sqlalchemy.sql import and_, case, distinct, func, or_, text

Expand Down Expand Up @@ -72,7 +73,8 @@ def format_date(cls, format, column: Column):
if format == "Week":
# DATE_FORMAT(install_date, '%Y-%m-%d') - INTERVAL (DAYOFWEEK(install_date) - 1) DAY,
date = func.date_format(column, "%Y-%m-%d")
return func.DATE_SUB(date, text(f"INTERVAL (DAYOFWEEK({column}) - 1) DAY"))
compiled = column.compile(dialect=mysql.dialect())
return func.DATE_SUB(date, text(f"INTERVAL (DAYOFWEEK({compiled}) - 1) DAY"))
if format == "Month" or format == "Mon":
return func.date_format(column, "%Y-%m-01")
if format == "Year":
Expand Down

0 comments on commit f744ee1

Please sign in to comment.