sqlparsingteradataregexp-replacesql-comments

Teradata SQL query parsing. Identify comments (using SQL)


I'm working on teradata log analysis and faced with issue that a lot of queries have comments. Can somebody help in REGEXP_REPLACE definition or may be advice some other way how to do it?

So task is to remove/replace query part with (it can be in any position in sql and may repeat):

  1. --text
  2. /* text */

I spent a lot of time on it and still get no good results.

I tried to use REGEXP_REPLACE but faced with problems:

  1. How to define 'end of line'. for comments defined as '--text'. Beginning -- till 'end of line'
  2. How to deal with several comments in query?

Solution

  • Findout how to do it:

    RegExp_Replace(SqlTextInfo,'[\t\r\n]|(--[^\r\n]*)|(/\*[\w\W]*?(?=\*/)\*/)')