Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column Extract Doesn't Work with Column Name of 'Range' and 'Section' #751

Open
jtnguyen2020 opened this issue Nov 15, 2023 · 0 comments
Open

Comments

@jtnguyen2020
Copy link

Describe the bug
select_query = 'select locid, locname, drn, pipelineid, pipelineshortname, loctype, subtype, facilitytype, town, range, section, segmentmilepost, milemarker, segmentname, locpro, zone, dirflow, statuscode, state, county, unsubscribedcapacity, latitude, longitude, pbgroupcode, enableparkloan, updwnpartydrn, scadastationcode, updatedt, createon, getdate() ap_import_time from table1'

To Reproduce
I ran the function below to get the columns but "range" and "section" didn't return as expected.

def find_selected_columns(select_query):
tokens = sqlparse.parse(query)[0].tokens
found_select = False
for token in tokens:
if found_select:
if isinstance(token, sqlparse.sql.IdentifierList):
return [
col.value.split(" ")[-1].strip("`").rpartition('.')[-1]
for col in token.tokens
if isinstance(col, sqlparse.sql.Identifier)
]
else:
found_select = token.match(
sqlparse.tokens.Keyword.DML, ["select", "SELECT"])
raise Exception("Could not find a select statement. Weird query :)")

Expected behavior
Columns "range" and "section" needs to be returned.

Versions (please complete the following information):

  • Python: [e.g. 3.8.8]
  • sqlparse: [e.g. 0.4.4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant