Обсуждение: Oracle to Postgres migration

Поиск
Список
Период
Сортировка

Oracle to Postgres migration

От
bimal maity
Дата:
Hi,

I have below query used in Oracle but while migrating to Postgres this code is not supported in Postgres.
Could you please tell me how to resolve this?

SELECT p.id_po, p.line_number, replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C, regexp_replace(p.protocol_number,'([[:cntrl:]])','', 'g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS protocol_number
                        ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C, regexp_replace(p.protocol_status,'([[:cntrl:]])','', 'g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS protocol_status
                        ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C, regexp_replace(p.protocol_approver,'([[:cntrl:]])','', 'g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS protocol_approver
                        ,max(p.protocol_date) AS protocol_date
                        ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C, regexp_replace(p.protocol_nota,'([[:cntrl:]])','', 'g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS protocol_nota
                        ,sum(coalesce(p.protocol_value,0)) protocol_value
                FROM podl_extended_protocol p
                where upper(p.protocol_status) not in ('REJEITADO','ELIMINADO')
                         group by p.id_po, p.line_number

Thanks,
Bimal

Re: Oracle to Postgres migration

От
Ilya Kosmodemiansky
Дата:
Hi Bimal,

On Fri, Dec 22, 2023 at 10:28 AM bimal maity <bimal.af2020@gmail.com> wrote:
> I have below query used in Oracle but while migrating to Postgres this code is not supported in Postgres.

I didn't try your query, but I guess it complains about RTRIM, because
it should accept text as an argument. If it is a case, you can try to dig in
direction of something like this:

> SELECT p.id_po, p.line_number, replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C,
regexp_replace(p.protocol_number,'([[:cntrl:]])','','g'))ORDER BY 1)::text 

(with explicit type casting)


best regards,
Ilya




--
Ilya Kosmodemiansky
CEO, Founder

Data Egret GmbH
Your remote PostgreSQL DBA team
T.: +49 6821 919 3297
ik@dataegret.com



Re: Oracle to Postgres migration

От
Thomas Kellerer
Дата:
bimal maity schrieb am 20.12.2023 um 04:35:
> Hi,
>
> I have below query used in Oracle but while migrating to Postgres this code is not supported in Postgres.
> Could you please tell me how to resolve this?
>
> SELECT p.id_po, p.line_number, replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C,
regexp_replace(p.protocol_number,'([[:cntrl:]])','','g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS
protocol_number
>                          ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C,
regexp_replace(p.protocol_status,'([[:cntrl:]])','','g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS
protocol_status
>                          ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C,
regexp_replace(p.protocol_approver,'([[:cntrl:]])','','g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS
protocol_approver
>                          ,max(p.protocol_date) AS protocol_date
>                          ,replace(replace(replace(RTRIM(XMLAGG(XMLELEMENT(name C,
regexp_replace(p.protocol_nota,'([[:cntrl:]])','','g'))ORDER BY 1), ',' ) ,'</C><C>','/'),'<C>',''),'</C>','') AS
protocol_nota
>                          ,sum(coalesce(p.protocol_value,0)) protocol_value
>                  FROM podl_extended_protocol p
>                  where upper(p.protocol_status) not in ('REJEITADO','ELIMINADO')
>                           group by p.id_po, p.line_number

What exactly does it do? I have often seen the hack using xmlagg/xmlelement/regexp_replace to do some kind of poor
man'sunnest/string_agg. 

If you tell us, what exactly the goal is, I am confident there is a better solution in Postgres.