Convert SQL Server views into PostgreSQL format |
[SQL Server to PostgreSQL Converter] [About Migration] [Types] |
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.
'TOP (100) PERCENT'
pattern, it must be
removed in PostgreSQL query. If there is another value in CREATE VIEW statement,
it can be replace by the following code in PostgreSQL:
SELECT ... LIMIT N;where N is number of rows to limit result of the query.
iif(condition, val1, val2)
that returns one of two
values depending on condition must be converted into
CASE WHEN condition THEN val1 ELSE val2 END;
'dbo'
must be replaced by
PostgreSQL equivalent 'public'
string1 + string2
must be
replaced by concat(string1,string2)
FOR XML PATH
syntax pattern
to merge fields into comma separated string:
SELECT distinct r.price, STUFF( (SELECT distinct ','+ Cast(a.code as varchar) FROM tbl_price a WHERE r.price = a.price FOR XML PATH(''), TYPE).value('.','VARCHAR(max)'), 1, 1, '') FROM tbl_price rThose queries must be rewritten using
STRING_AGG
in PostgreSQL:
SELECT price, string_agg(DISTINCT code::varchar,',') code FROM tbl_price GROUP BY price
Have questions? Contact us