在 python 中,我们有 x 个不同的 sql,目标是对它们进行排序,以便它们可以按顺序执行(即,如果您对 tableA 的插入依赖于 tableB,则必须首先插入 tableB)
python 片段:
unordered_sqls = [
'insert into jj select * from hh',
'insert into hh select jj from pp, oo',
'insert into pp select * from n',
'insert into q select sumtin from ee'
]
# todo_some_antlr_magic_to_sort
# yes, the write to pp and q could happen in parallel
# so not worried which of those 2 come first.
# as they are sourced from n and ee (which we don't write to)
# they can be first in what we control
expected_ordered_sqls = [
'insert into pp select * from n',
'insert into q select sumtin from ee',
'insert into hh select jj from pp, oo',
'insert into jj select * from hh'
]