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.
SELECT ... OFFSET X LIMIT Y
is converted into
SELECT ... OFFSET X ROWS FETCH NEXT Y ROWS ONLY;
POSITION
must be reiplaced by
SQL Server equivalent CHARINDEX
$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 |
DATE_PART
must be replaced by DATEPART
NOW()
must be converted into SQL Server GETDATE
COALESCE
must be replaced by ISNULL
REPEAT
must be converted into SQL Server equivalent REPLICATE