question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with Postgres dates and times in queries

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
dan-leecommented, Jul 1, 2020

@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.

8reactions
Taho2007commented, May 21, 2020

This big issue makes “Hasura” almost worthless thing. We may not use “intervals” for datetime comparisons in “where” clause. BAD.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found