Revision 10841
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sql.py | ||
---|---|---|
1563 | 1563 |
'''For kw_args, see tables()''' |
1564 | 1564 |
for table in tables(db, schema, **kw_args): truncate(db, table, schema) |
1565 | 1565 |
|
1566 |
def distinct_table(db, table, distinct_on, joins=None): |
|
1566 |
def distinct_table(db, table, distinct_on, joins=None, conds=None):
|
|
1567 | 1567 |
'''Creates a copy of a temp table which is distinct on the given columns. |
1568 | 1568 |
Adds an index on table's distinct_on columns, to facilitate merge joins. |
1569 | 1569 |
@param distinct_on If empty, creates a table with one row. This is useful if |
1570 | 1570 |
your distinct_on columns are all literal values. |
1571 | 1571 |
@param joins The joins to use when creating the new table |
1572 |
@param conds Any additional filters to use when creating the new table |
|
1572 | 1573 |
@return The new table. |
1573 | 1574 |
''' |
1574 | 1575 |
if joins == None: joins = [table] |
... | ... | |
1583 | 1584 |
else: add_index(db, distinct_on, table) # for join optimization |
1584 | 1585 |
|
1585 | 1586 |
insert_select(db, new_table, None, mk_select(db, joins, |
1586 |
[sql_gen.Col(sql_gen.all_cols, table)], distinct_on=distinct_on,
|
|
1587 |
[sql_gen.Col(sql_gen.all_cols, table)], conds, distinct_on,
|
|
1587 | 1588 |
order_by=None, limit=limit)) |
1588 | 1589 |
analyze(db, new_table) |
1589 | 1590 |
|
Also available in: Unified diff
lib/sql.py: distinct_table(): support custom filters on the distincting query