Search code examples
snowflake-cloud-data-platformnetezza

Netezza to snowflake Replace, Trim, XML function conversion


We recently migrated our data servers from Netezza to Snowflake and all SQL queries that were originally running in Netezza need to be translated to be compatible to run in snowflake. I'm not able to translate the following syntax from netezza to snowflake. Can someone please help? Thanks

,trim(trailing ',' from replace(replace (XMLserialize(XMLagg(XMLElement('X',date(orderdate)))), '<X>','' ),'</X>' ,',' )) as orderdate

I tried using REGEX_REPLACE function from snowflake but that didn't work.


Solution

  • In general when translating code it is better to focus on the behavior instead of trying to literally translate it.

    Based on how the code is written, i.e. generating XML element, aggregating multiple elements, replacing of <X>, </X> and removal of trailing , it seems it is generating comma-separated string of dates.

    In Snowflake:

    LISTAGG(TO_VARCHAR(orderdate, 'YYYY-MM-DD'), ',') AS orderdate