Aggregating by month: "user-defined function raised exception"
See original GitHub issueHi,
I’m trying to extract month from date
column in my database. Just as it’s shown here.
Here is my code:
query = (dc.Message.select(dc.Message.date.month.alias('month')).limit(5))
for q in query:
print(q.month)
And Message model:
class Message(BaseModel):
text = CharField(null = True)
created_by = ForeignKeyField(User)
posted_in = ForeignKeyField(Chat)
date = DateTimeField()
When I try to execute my code, I get this message in debug console:
peewee.OperationalError: user-defined function raised exception
Do you have any ideas how to fix that?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
user-defined function raised exception occurred - Stack Overflow
Show activity on this post. I have following error when I'm using below user defined function with raw query: Django Version: ...
Read more >Compute Functions — Apache Arrow v10.0.1
The grouped aggregation functions raise an exception instead and need to be used ... PyArrow allows defining and registering custom compute functions.
Read more >Built-in functions | Databricks on AWS
Learn about built-in functions in Databricks SQL and Databricks Runtime. ... Aggregates elements in an array using a custom aggregator.
Read more >when other than exception, and raise application error
UTL_FILE raises about 5 or 6 different "user defined exceptions" -- i use raise_application_error ... COM> show err Errors for FUNCTION FOO: LINE/COL...
Read more >Query Expressions - Django documentation
All of the aggregate functions, like Sum() and Count() , inherit from ... window functions in the WHERE clause and Django raises an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is that the datetime strings contain timezone information, which is not supported by these methods. If using SQLite, which does not contain a native datetime type, dates are stored in a text column in a format that ensures lexicographic ordering (so sorting and comparing datetimes works as you’d expect). You have the format correct (Y-m-d H:M:S) but the inclusion of the timezone will make ordering not work correctly (unless all values have the same timezone, which, if the case, means you can probably do without storing it anyways?). So to use the helper functions with SQLite, you’ll want to store all datetimes as naive datetimes. If you use timezones, just convert to UTC before storing and convert back to local-time before using them in your application.
You should be able to cast as an integer. Sqlite Cast docs: