Home > Documentation > PostgreSQL to MS SQL
Convert PostgreSQL views into SQL Server format |
[PostgreSQL to SQL Server Converter] [Migrate Triggers] [Types Mapping] |
When migrate a database from SQL Server to PostgreSQL one of the steps is conversion of views into the destination format. 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
MS SQL 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