简体   繁体   English

Query_to_xml 结果为空

[英]Query_to_xml result is empty

I have the following problem and I hope you can help me:我有以下问题,希望你能帮助我:

If I run the following query on my postgresDB, I get a resultset where the id is '123'如果我在我的 postgresDB 上运行以下查询,我会得到一个 ID 为“123”的结果集

SELECT * 
FROM public.table 
WHERE public.table.id = '123';

But I need to get the result in XML format.但我需要得到 XML 格式的结果。 So I run the following query所以我运行以下查询

SELECT query_to_xml('SELECT * from public.table WHERE public.table.id = CAST(123 as varchar)', TRUE, FALSE, '');

Unfortunately I get an empty table as a result.不幸的是,结果我得到了一张空桌子。 I don't understand the difference between the 2 queries.我不明白这两个查询之间的区别。

Result:结果:

 <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

 </table>

Note: The column 'id' is of type varchar in my case.注意:在我的例子中,“id”列的类型是varchar

I'm not a native English speaker, so sorry for grammar mistakes.我不是以英语为母语的人,所以对语法错误感到抱歉。 I'm also new to databases.我也是数据库新手。 So I hope it's not a stupid question.所以我希望这不是一个愚蠢的问题。

Thank you for your assistance.谢谢您的帮助。

as per comments the problem may arise because the data casting, to keep the query comparing without casting, the solution is to escape the quotes with two single quotes:根据评论,可能会出现问题,因为数据转换,为了保持查询比较而不进行转换,解决方案是用两个单引号转义引号:

SELECT query_to_xml('SELECT * from public.table WHERE public.table.id = ''123''', TRUE, FALSE, '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM