Search code examples
postgresqlelixirecto

Querying date/time on 2 columns


I have a column date and column time on my PostgreSQL table. I wish to make a query, to filter rows that are not expired based on date and time. I tried this, but it does not works and returns an error Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or nea:

from q in Line, where: fragment("date ? + time ? > NOW()", q.date, q.time)

Solution

  • I think this problem can be solved by not using time and date prefixes:

    from q in Line, where: fragment("? + ? > NOW()", q.date, q.time)
    

    or even

    from q in Line, where: q.date + q.time < fragment("NOW()")
    

    Provided, your columns have the correct data type