Working with Postgres dates and times in queries
See original GitHub issueIs there any documentation on what Postgres operators are available when querying/setting dates/times? It’s awesome that I can make a query like this (note the now()
in where
and _set
):
mutation ConfirmEmail($token: String!) {
update_email_confirmation(
where: { token: { _eq: $token }, created_at: { _lt: "now()" } }
_set: { confirmed_at: "now()" }
) {
returning {
email_confirmation_id
email
created_at
confirmed_at
}
}
}
I’d love to be able to subtract 30 days from the now()
in the where clause, e.g.:
mutation ConfirmEmail($token: String!) {
update_email_confirmation(
where: { token: { _eq: $token }, created_at: { _gt: "now() - interval '29' day" } }
_set: { confirmed_at: "now()" }
) {
returning {
email_confirmation_id
email
created_at
confirmed_at
}
}
}
But I’m missing something, or this isn’t yet supported:
{
"errors": [
{
"extensions": {
"path": "$",
"code": "data-exception"
},
"message": "invalid input syntax for type timestamp with time zone: \"now() - interval '29' day\""
}
]
}
Anyone have any hints on how I can query for something “within the past 30 days”?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How to Query Date and Time in PostgreSQL - PopSQL
How to Query Date and Time in PostgreSQL. Get the date and time time right now: select now(); -- date and time select...
Read more >Working with Date and Time Functions in PostgreSQL
This article will show the implementation of date and time functions in PostgreSQL.
Read more >9.9. Date/Time Functions and Operators - PostgreSQL
All the functions and operators described below that take time or timestamp inputs actually come in two variants: one that takes time with...
Read more >Exploring Postgres date formats and their different functions
In this article, we will explore Postgres dates, the different date data types, uses and functions. Date and timestamps are helpful for data ......
Read more >Working with Dates and Times - Postgres Guide
A common activity with any database or programming language is interacting with dates and times. Postgres has several date and time datatypes as...
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 Free
Top 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
@Taho2007 your comment sounds like a typical donald trump tweet…
anyway, the date functionality would be greatly appreciated. though, it’s not too hard to make it work on implementation side.
This big issue makes “Hasura” almost worthless thing. We may not use “intervals” for datetime comparisons in “where” clause. BAD.