Convert this SQL Server query to PostgreSQL

Viewed 32

This is my SQL Server query ;

UPDATE [dbo].[tablename] 
SET [Tarih] = DATEADD(DAY,(SELECT DATEDIFF(DAY, MAX([date]), GETDATE())-1 
                           FROM [dbo].[tablename]), [date])

How can I convert this query to run in PostgreSQL?

Thanks you for any help. :D

1 Answers

I was able to come this far. the error I got:operator does not exist: date + double precision

        WITH stat AS (
SELECT MAX(a.actiontime)::date AS actiontime
FROM
extable a )
UPDATE extable n set n.actiontime=(CURRENT_DATE + (select DATE_PART('day',stat.actiontime)- DATE_PART('day',now()::date))-1)::timestamp from stat
Related