sqlpostgresqlsqlcode

How to rewrite SQL for PostgreSQL


I'm trying to rewrite two pieces of SQL Server code to PostgreSQL.

The 1st one is:

WHERE
    (DATEADD(S, Submit_Date, '1970-01-01')) >= DATEADD(d, -3, GETDATE())
    OR
    (DATEADD(S, Last_Changed_Date, '1970-01-01')) >= DATEADD(d, -3, GETDATE())

I keep getting an error regarding the S after the DATEADD.

The 2nd one is this:

WHERE (dbo.Test.[Log] LIKE '%%Status: Closed%%')
GROUP BY dbo.PYR.ID_Number

I need help for the mentioned SQL Server code lines to be modified for PostreSQL.

Any suggestions how they should be?

Thank you.


Solution

  • WHERE
    ('1970-01-01'::timestamp + interval '1 second' * submit_date)  >= now()+interval '-3 days'
    OR
    ('1970-01-01'::timestamp + interval '1 second' * Last_Changed_date)  >= now()+interval '-3 days'
    
    WHERE  (dbo.Test."Log" ILIKE '%%Status: Closed%%')
    GROUP BY dbo.PYR.ID_Number