sql-metadata icon indicating copy to clipboard operation
sql-metadata copied to clipboard

Parser.columns drops column named 'source' when it is the last column in a SELECT statement

Open gkcivis opened this issue 2 months ago • 0 comments

Hello, if a column named 'source' is the last column in a SELECT statement, it gets dropped from the list returned by Parser(sql_str).columns. If 'source' is moved to another place in the SELECT statement, it is not dropped. I can recreate this issue in v2.18.0 as well as in the interactive demo (https://sql-app.infocruncher.com/). I would not expect 'source' to get dropped if it's the last column in a SELECT statement.

from sql_metadata import Parser

sql_query_str = 'select foo, bar, source from my_table'
Parser(sql_query_str).columns
# ['foo', 'bar']

sql_query_str = 'select foo, source, bar from my_table'
Parser(sql_query_str).columns
# ['foo', 'source', 'bar']

gkcivis avatar Nov 03 '25 18:11 gkcivis