I use concatenation to prepare a query string with parameter values
When I use single quotes:
p_ReqStr_old := '
with prm as
(
select
1::int4 as id, ' || '
to_timestamp(''' || to_char(p_BegRepDate, 'DD.MM.YYYY') || ''',''DD.MM.YYYY'')::timestamp as p_BegDate,
to_timestamp(''' || to_char(p_EndRepDate, 'DD.MM.YYYY') || ''',''DD.MM.YYYY'')::timestamp as p_EndDate, ' ||
cast(p_IsIncludeTestLpu as varchar(1)) || '::int8 as p_IsIncludeTestLpu
)';
I receive the following result:
with prm as
(
select
1::int4 as id,
to_timestamp('01.01.2023','DD.MM.YYYY')::timestamp as p_BegDate,
to_timestamp('31.01.2023','DD.MM.YYYY')::timestamp as p_EndDate, 2::int8 as p_IsIncludeTestLpu
)
When I use dollar quoting:
p_ReqStr_new := $$
with prm as
(
select
1::int4 as id,
to_timestamp(to_char(p_BegRepDate, 'DD.MM.YYYY'), 'DD.MM.YYYY')::timestamp as p_BegDate,
to_timestamp(to_char(p_EndRepDate, 'DD.MM.YYYY'), 'DD.MM.YYYY')::timestamp as p_EndDate,
cast(p_IsIncludeTestLpu as varchar(1))::int8 as p_IsIncludeTestLpu
)$$;
I receive this undesirable result:
with prm as
(
select
1::int4 as id,
to_timestamp(to_char(p_BegRepDate, 'DD.MM.YYYY'), 'DD.MM.YYYY')::timestamp as p_BegDate,
to_timestamp(to_char(p_EndRepDate, 'DD.MM.YYYY'), 'DD.MM.YYYY')::timestamp as p_EndDate,
cast(p_IsIncludeTestLpu as varchar(1))::int8 as p_IsIncludeTestLpu
)
Is there a way to receive a result with date values with dollar quoting mechanics?