From:       To:      
Home > Documentation > PostgreSQL to SQL Server

Convert PostgreSQL views into SQL Server format

[PostgreSQL to SQL Server Converter]  [Migrate Triggers]  [Types Mapping

During database migration from SQL Server to PostgreSQL, conversion of views is one of the most important and complicated steps. This whitepaper discovers basic rules of this conversion.

  1. SELECT ... OFFSET X LIMIT Y is converted into
    SELECT ... OFFSET X ROWS FETCH NEXT Y ROWS ONLY;
    

  2. PostgreSQL built-in function POSITION must be reiplaced by SQL Server equivalent CHARINDEX
  3. PostgreSQL expression $date + $interval must be converted into SQL Server function call DATEADD($interval, $n_units, $date) according to the table below:

    PostgreSQL Interval SQL Server Equivalent
    ($date + $n_units * interval '1 day')::date DAY/DD/D
    ($date + $n_units * interval '1 hour')::date HOUR/HH
    ($date + $n_units * interval '1 minute')::date MINUTE/MI/N
    ($date + $n_units * interval '1 month')::date MONTH/MM/M
    ($date + $n_units * interval '1 second')::date SECOND/SS/S
    ($date + $n_units * interval '1 week')::date WEEK/WW/WK
    ($date + $n_units * interval '1 year')::date YEAR/YY

  4. Every occurrence of DATE_PART must be replaced by DATEPART
  5. PostgreSQL function NOW() must be converted into SQL Server GETDATE
  6. Every occurrence of COALESCE must be replaced by ISNULL
  7. PostgreSQL function REPEAT must be converted into SQL Server equivalent REPLICATE