Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, everyone. I have difficulties translating a query from sql to postgresql. The query in sql is:

SELECT Stuff((SELECT N', ' + reference_number + '_' + report_name
			                    FROM tbl_report_definition
			                    WHERE report_definition_id in
				                    (SELECT report_definition_id
				                    FROM tbl_report_definition_columns
				                    WHERE report_header_id = rh.id)
		                    FOR XML PATH('') ,TYPE)
		                    .value('text()[1]','nvarchar(max)'),1,2,N'')

I researched and find that postgresql equivalent of sql "stuff" is
overlay
so my postgre sql query is:

SELECT overlay((SELECT N', ' + reference_number + '_' + report_name
			                    FROM tbl_report_definition
			                    WHERE report_definition_id in
				                    (SELECT report_definition_id
				                    FROM tbl_report_definition_columns
				                    WHERE report_header_id = rh.id)
		                    FOR XML PATH('') ,TYPE)
		                    .value('text()[1]','nvarchar(max)') placing N'' from 1 for 2)


But when I executed this query in pgadmin I received the following error message:

syntax error at or near "XML" LINE 15: FOR XML PATH('') ,TYPE)


Can you help me to translate my sql query to postgre right?

What I have tried:

I tried to find how to translate this code block "
FOR XML PATH('') ,TYPE
" from sql to postgre sql but without success.
Posted
Updated 27-Mar-19 3:08am

1 solution

A simple google search resulted in this:

SQL
SELECT table_to_xml('users', true, false, '');

--Or

SELECT query_to_xml('SELECT * FROM users', true, false, '');


I leave you to your mad google skillz if this isn't sufficient to get you started.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900