regex - How could I delete sql functions format in awk? -
i've got sql query looks this:
select test1(func1(myfield)), test2(max(myfield), lower("nope")), test3(max(myfield), 1234), avg(test1(test2(myfield, func1(4)))), func2(upper("stack")) substr(myfield, 2, 4), test2(min(myfield), substr(lower(upper("nope")), 1, 7)), substr('func1(', 2, 4) mytable;
then i'm trying remove functions called:
- test1
- test2
- test3
- func1
- func2
but preserving avg, max, upper, substr... , native functions.
so desired output be:
select myfield, max(myfield), max(myfield), avg(myfield), upper("stack") substr(myfield, 2, 4), min(myfield) substr('func1(', 2, 4) mytable;
i want remove lower of second line because, argument of 1 of functions delete, in case test2, has 2 parameters. if delete function, should delete params well.
i've tried way in awk:
{ print gensub(/(test1|test2|func1|func2)\(/,"","gi", $0); }
but output doesn't have account right parentheses, doesn't delete rest of parameters of custom functions:
select myfield)), max(myfield), lower("nope")), max(myfield), 1234), avg(myfield, 4)))), upper("stack")) substr(myfield, 2, 4), min(myfield), substr(lower(upper("nope")), 1, 7)), substr('', 2, 4) mytable;
any idea or clue handle situation?
you rename functions' names built-in functioncoalesce
while keep brakets (
)
, other params of users' functions. produce same result, not syntactically, work same unless built-in functions don't return null
values. easier achieve because don't have worry brakets.
if file
input provide, then:
cat file | sed 's#\(test1\|test2\|func1\|func2\)(#coalesce(#g'
will produce:
select coalesce(coalesce(myfield)), coalesce(max(myfield), 4), avg(coalesce(coalesce(myfield, coalesce(4)))), coalesce(upper("stack")) mytable;
Comments
Post a Comment