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

Support statement types similar to referenced relations #118

Open
raghu2 opened this issue Feb 20, 2023 · 3 comments
Open

Support statement types similar to referenced relations #118

raghu2 opened this issue Feb 20, 2023 · 3 comments

Comments

@raghu2
Copy link

raghu2 commented Feb 20, 2023

Hi @lelit ,

Not sure if this was already implemented, but it would be great if something like statement type can also be implemented like

query = 'insert into table_1 select * from table_2'

should give something like [('InsertStmt', 'table_1'), ('SelectStmt', 'table_2')]

If this was already implemented please guide me to the link or the code-snippet.

Thanks in advance,
Raghu.

@lelit
Copy link
Owner

lelit commented Feb 20, 2023

Without going into details (but we know what|who hides there 😉) it seems easy to adapt the ReferencedRelations to do that, keeping track of the "statement" type in its visit_SelectStmt() method, possibly adding a new attribute by_stmt_type_names, a dictionary of sets.

@raghu2
Copy link
Author

raghu2 commented Feb 20, 2023

thanks @lelit for your quick response. can you guide me as to how to proceed please ? i will try to fork and raise a pr accordingly.

@lelit
Copy link
Owner

lelit commented Feb 20, 2023

I would start by copying the ReferencedRelations class into a standalone script, where you can experiment freely.
I would then add by_stmt_type_r_names attribute, initialized as an empty dictionary (or even a defaultdict(set) instance).
Then, whenever the code adds a name to the existing r_names set, it should also add the same name to the right set in by_stmt_type_r_names, creating the set if it does not already exist.

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

2 participants