我正在使用liquibase
创建函数,并试图在SQL中使用<
运算符时出错。
SQL:
<createProcedure>
CREATE OR REPLACE FUNCTION function(dateFrom timestamp, dateTo timestamp )
RETURNS TABLE
LANGUAGE plpgsql
AS $$
BEGIN
SELECT * FROM
ORDER BY date DESC
WHERE date >= $2 AND date < $3
RETURN QUERY;
END;
$$;
</createProcedure>
错误:
元素的内容必须包含格式正确的字符数据或标记。
在WHERE date >= $2 AND date < $3
答案 0 :(得分:1)
XML不允许在标签的值内使用<
或>
,除非您将该标签的内容包装到CDATA
节中:
<createProcedure>
<![CDATA[
CREATE OR REPLACE FUNCTION function(dateFrom timestamp, dateTo timestamp )
RETURNS TABLE
LANGUAGE plpgsql
AS $$
BEGIN
SELECT * FROM
ORDER BY date DESC
WHERE date >= $2 AND date < $3
RETURN QUERY;
END;
$$;
]]>
</createProcedure>
与Liquibase问题无关:包装简单SQL查询的函数最好定义为SQL函数,以避免PL / pgSQL开销:
<createProcedure>
<![CDATA[
CREATE OR REPLACE FUNCTION function(dateFrom timestamp, dateTo timestamp )
RETURNS TABLE (...)
LANGUAGE sql
AS $$
SELECT *
FROM ...
WHERE date >= $2
AND date < $3
ORDER BY date DESC
$$;
]]>
</createProcedure>