F
Friedman, Jason
I have lines that look like this:
select column1, 'select' as type
from table
where column2 = 'foo'
I want to return:
SELECT column1, 'select' AS type
FROM table
WHERE column2 = 'foo'
This is SQL with the keywords converted to uppercase. Note that the
second "select" string is not a keyword and thus I do not want to
convert it to uppercase. Thus, I don't think the string.replace()
method will work for me.
With Perl I might do something like this:
$line =~ s/(select)/uc($1)/e;
More generally:
for $keyword in (@keyword) {
$line =~ s/($keyword)/uc($1)/e;
}
How would I do this with Python?
select column1, 'select' as type
from table
where column2 = 'foo'
I want to return:
SELECT column1, 'select' AS type
FROM table
WHERE column2 = 'foo'
This is SQL with the keywords converted to uppercase. Note that the
second "select" string is not a keyword and thus I do not want to
convert it to uppercase. Thus, I don't think the string.replace()
method will work for me.
With Perl I might do something like this:
$line =~ s/(select)/uc($1)/e;
More generally:
for $keyword in (@keyword) {
$line =~ s/($keyword)/uc($1)/e;
}
How would I do this with Python?