Skip to content

How to delete all columns from select and add Star to query? (modifying) #1357

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

You must be logged in to vote

found solution

def transformer(node):
	# print("->")
	# print(type(node))
	# print("->")

	if isinstance(node, sqlglot.exp.Select):
		s = node.find_all(sqlglot.exp.Column,sqlglot.exp.Alias) 
		for col in s:
			if col.parent == node:
				col.pop()

		node.select('*',copy = False)
		# print(node)
	return node



i =0 
for s in parse:
	if s is not None:
		# print(type(s))
		# print(s.transform(transformer).sql())
		parse[i]= s.transform(transformer)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RedHotUnicorn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant