Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date format with Postgres #242

Open
JRII972 opened this issue Apr 17, 2024 · 2 comments
Open

Date format with Postgres #242

JRII972 opened this issue Apr 17, 2024 · 2 comments

Comments

@JRII972
Copy link

JRII972 commented Apr 17, 2024

When i try use date column with postgres db, it fail on date format

(psycopg2.errors.UndefinedFunction) function date_format(date, unknown) does not exist

image

when i check the code, the 'date_format' function is hard coded

insights/insights/doctype/insights_query/insights_assisted_query.py

def add_format_options(result_column):
            result_column["format_options"] = {}
            result_column["type"] = get_inferred_column_type(result_column)
            for qc in query_columns:
                label_matches = qc.get("label") == result_column.get("label")
                alias_matches = qc.get("alias") == result_column.get("label")
                if not label_matches and not alias_matches:
                    continue
                result_column["label"] = qc.get("alias") or qc.get("label")
                # temporary fix until we change format_options in result columns from dict to str
                result_column["format_options"] = {"date_format": qc.get("granularity")}
                result_column["type"] = qc.get("type")
                break
            return frappe._dict(result_column)
@nextchamp-saqib
Copy link
Member

Can you share the generated SQL for this query?

@JRII972
Copy link
Author

JRII972 commented May 14, 2024

Sorry i was in vacation

image

SELECT date_format(covid.jour, '%%Y-%%m-%%d 00:00') AS "Group by Jour",
       avg(covid.tx_prev_hosp) AS "Avg of Tx Prev Hosp"
  FROM covid AS covid
 GROUP BY date_format(covid.jour, '%%Y-%%m-%%d 00:00')
 LIMIT 500

date_format is the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants