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

sql execution engine throws an error when a sql having a DATE() function #1650

Closed
manmustbecool opened this issue May 18, 2023 · 1 comment
Closed
Assignees

Comments

@manmustbecool
Copy link

from sqlglot.executor import execute

output = execute(
    "select id from orders where timestamp>Date('now', '-1 day')",
    tables={"orders": [
        {"id": 1, "timestamp": "2023-01-02"},
        {"id": 2, "timestamp": "2023-01-02"},
    ]})

Error message

sqlglot.errors.ExecuteError: Step 'Scan: orders (1460336550880)' failed: name 'DATE' is not defined
@tobymao tobymao self-assigned this May 18, 2023
@tobymao
Copy link
Owner

tobymao commented May 18, 2023

you need to transpile it to interval form

from sqlglot.executor import execute

execute(
    "select id from orders where CAST(timestamp AS DATETIME)> currenttime() - interval '1' day",
    tables={"orders": [
        {"id": 1, "timestamp": "2023-05-18"},
        {"id": 2, "timestamp": "2023-01-02"},
]})

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
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