Skip to main content
Community site session details

Community site session details

Session Id : 51sScdARDrHELG64U1c1yC
Power Automate - Using Connectors
Unanswered

POSTGRES ODATA time comparison

Like (0) ShareShare
ReportReport
Posted on 6 Sep 2018 16:22:58 by 8

I am trying to get all records from a postgres database where the date_completed (timestamp without timezone) is between startoftoday and endoftoday. However I cannot get the ODATA query for less than or greater than to work. I keep getting this error. 

 

{
 "status": 400,
 "message": "We cannot apply operator < to types DateTime and DateTimeZone.\r\n inner exception: We cannot apply operator < to types DateTime and DateTimeZone.\r\nclientRequestId: 12f42943-0acf-4b4a-a482-3d72ca9dbf98",
 "source": "postgresql-eus.azconn-eus.p.azurewebsites.net"
}

The odata filter is equal to 

utcnow('yyyy-MM-ddTHH:mm:ssZ’) lt date_completed

 This is the odata filter after the expressions run

2018-09-06T08:07:16Z lt date_completed
  • degvalentine Profile Picture
    193 on 10 May 2019 at 19:36:22
    Re: POSTGRES ODATA time comparison

    Couldn't use Azure Functions to access my database because it's on-prem and I don't want to pay for a VPN Gateway.

  • degvalentine Profile Picture
    193 on 10 May 2019 at 16:49:34
    Re: POSTGRES ODATA time comparison

    @ialastairhunter  2 great suggestions - Thank you!

     

    The OData workaround was a bit painful as you suggested, but it works. Doing a "my_ts >= yyyy-mm-dd" filter ended up looking like this (for any that might find this thread later):

    year(my_ts) gt yyyy or (year(my_ts) eq yyyy and (month(my_ts) gt mm or (month(my_ts) eq mm and day(my_ts) ge dd)))

    I'll try the Azure Function next and post results (and probably code).

  • ialastairhunter Profile Picture
    10 on 10 May 2019 at 01:39:45
    Re: POSTGRES ODATA time comparison

    @degvalentine 

     

    There are a few aditional options

    1 - Create an Azure Function app that would take a HTTP Post with a sql query string and return JSON Object with the query results. Then use an HTTP Connector in flow to pass a SQL Query to the azure function app. 

    2 - Use an Azure Logic app instead of flow and you can call an azure function app, or execute some javascript right from the azure logic app. 

     

  • ialastairhunter Profile Picture
    10 on 10 May 2019 at 01:17:30
    Re: POSTGRES ODATA time comparison

    @degvalentineI was able to solve this however it was not an ideal query. You will need to use the MONTH, DAY, and YEAR Functions in combintation with the greate than and less than operators. 

     

    For example if you wanted to compare the date was equal to 04/04/2013

    month(DATE) eq 04 AND day(DATE) eq 04 AND year(DATE) eq 2013

     

  • degvalentine Profile Picture
    193 on 10 May 2019 at 00:26:01
    Re: POSTGRES ODATA time comparison

    I'm in the same boat. My research leads me to believe there is no solution. I hope I'm wrong and am still searching...

     

    • our PG timestamp without time zone columns are considered "DateTime" fields in OData
    • OData intentionally dropped support for DateTime in some prev update (many years ago)
    • OData community is/was livid (https://github.com/OData/WebApi/issues/136) but apparently there's no intent to restore it

    I believe our only hope is that Flow will add support for "Execute a query" to on-prem gateways. Here's a link to the community topic. Add your vote!

  • elksson Profile Picture
    8 on 07 Sep 2018 at 15:51:33
    Re: POSTGRES ODATA time comparison

    IMG_0977.pngIMG_0978.png

  • elksson Profile Picture
    8 on 07 Sep 2018 at 15:26:13
    Re: POSTGRES ODATA time comparison

    Using filter contains '2018-09-05' works but since the table has over a million rows the query takes 22 mins to execute if I don’t use the database engine to filter the results.

     

    I will try the filter as you suggested but im sure if it does work the same issue will exist as the table just has too many rows. 

  • v-yuazh-msft Profile Picture
    on 07 Sep 2018 at 06:58:10
    Re: POSTGRES ODATA time comparison

    Hi @elksson,

     

    Could you please share a screenshot of the configuration of your flow?

     

    Please take a try to add a "Filter array" action in your flow replace of the ODATA query, the flow should as below:

    Capture.PNG

     

     

    Best regards,

    Alice

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Featured topics

Loading complete