Skip to content

Altering an explicit select statement to select all: select a, b, c -> select * #267

Closed Answered by barakalon
ThomasHepworth asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Tom -

Certain expression types have methods for altering certain clauses. For example, see Select.select:

>>> expression = sqlglot.parse_one("select a, b, c")
>>> expression = expression.select("*", append=False)
>>> print(expression)
SELECT *

Note the append=False argument - this overwrites the selects instead of appending to the list.

By default, this method copies the expression before altering it. If you prefer to edit the expression in-place, set copy=False.

These "builder" methods can't yet be used to remove clauses, but I don't see why we couldn't add that functionality...

For now, to remove clauses, you can use set, which is available on all expression types:

>>> expression = s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ThomasHepworth
Comment options

Answer selected by tobymao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants