Support statement types similar to referenced relations
Opened this issue · 3 comments
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.
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.
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.
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 add
s 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.